Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    SmartGWT + Selenium IDE, DynamicForm.validate() fails

    I've been trying to get Selenium IDE working with the SmartGWT application we are building and we seem to be having lots of problems. Specifically, submitting a DynamicForm with required fields and using .validate() does not work as expected - validate() fails thinking that the required fields are empty while I can clearly see that the Selenium IDE populates the fields with type command.

    Here is a simplified code block for the log in form. It works just fine when done by hand but running Selenium script fails validation by resetting the login and passwor fields to blank and flagging each field as "required".

    If I remove .setRequired(true), Selenium IDE script runs just fine taking both fields' values and passing further to the server. Same story (works great) if I just remove the loginForm.validate() -- fields' values are sent to the server. I can't explain why validate() doesn't like Selenium's populated fields.

    Code:
            String PAGE_BASE_ID = "login"
            DynamicForm loginForm = new DynamicForm();
            loginForm.setID(PAGE_BASE_ID + "_form");
    
            TextItem userLoginItem = new TextItem();
            userLoginItem.setTitle("Login");
            userLoginItem.setRequired(true);
    
            PasswordItem passwordItem = new PasswordItem();
            passwordItem.setTitle("Password");
            passwordItem.setRequired(true);
    
            userLoginItem.setName("LOGIN_FIELD");
            passwordItem.setName("PASSWD_FIELD");
    
            Button loginButton = new Button("Login");
            loginButton.setID(PAGE_BASE_ID + "_loginButton");
    
            loginForm.setFields(userLoginItem, passwordItem);
    
            VStack pageBody = new VStack();
            pageBody.addMember(loginForm);
            pageBody.addMember(loginButton);
    
            loginButton.addClickHandler(
                new ClickHandler() {
                    @Override
                    public void onClick(ClickEvent event) {
                        if(loginForm.validate()){
                             login(); //mockup, actually an RPC call goes here
                        }
                    }
                }
            );
    Thanks.

    #2
    Are you loading the SmartGWT Selenium extensions and have you read the user guide? See the "selenium" directory at the top level of your SDK.

    Comment


      #3
      Yes and yes, but you are right, I guess I didn't try to understand scLocator syntax completely in the guide. It appears that the recorder does not recognize the locators correctly so I had to manually alter the commands. Not a big deal and I can live with that. Thank you very much for drawing my attention to the guide again.

      I am still having problems with click command on the buttons that submit forms. The button gets highlighted but no event is actually being fired. My guess is this is also scLocator related problem and looking at the available commands, they all look very weird: //div[5]/div/div/div/div[4]/div/div[2]/div/div[2]/div/table/tbody/tr/td

      Does it matter if the button is part of a different Layout from the form it's submitting? We're using ClickHandler anyway.

      Code:
      List<Button> ewButtons = new ArrayList<Button>();
      ewCreateButton = new Button("Create");
      ewCreateButton.setID("secCfg_Wzrd_CreateButton");
      ewButtons.add(ewCreateButton);
      
      layout.addMember(addButtonRow(ewButtons));
      
      ewCreateButton.addClickHandler(
                  new ClickHandler() {
                      @Override
                      public void onClick(ClickEvent event) {
                          save();
                      } 
                  }
              );
      Code:
      Selenium command: click
      target: scLocator=//Button[ID="secCfg_Wzrd_CreateButton"]/

      Comment


        #4
        After some investigation we've determined the problem is likely due to the "type" command.
        The Selenium IDE recorder plugin should be recording an "scLocator" when you're typing in a form item but it appears this has become broken at some point, so it'll record a simpler (and less reliable within the SmartGWT application) identifier such as DOM ID.
        We've now made a change to the selenium-extension-ide.js file to ensure such a locator does get recorded.

        Secondly - in the selenium-extension.js file (used during playback) we were relying on the locator being an "scLocator" to ensure the form item logically updated to pick up the user-entered value. If this was not present while the value would update on the screen the form item would not be notified on the change - very likely to cause the behavior you describe where the values look right but things like validation fail.
        We've also made a change to resolve this - now even if your locator simply refers to the DOM ID of a form item's text-box element we should correctly pick up the updated value when playing back a "type" command.

        So - the underlying issue should be fixed in nightly builds going forward (currently on the 3.0d branch only but we will likely port to 3.0p after some more testing).
        For now you should be able work around this by modifying your "type" commands to use an scLocator to point at the form item in question.

        You'll have to enter this by hand since the recorder doesn't pick this up for you.
        A quick tip - you can determine the scLocator for a form item input box by opening the developer console, hitting the "enable auto test" link, then clicking on the text box in question.
        The locator string should show up in the developer console and can be copied / pasted into your test script.

        Regards
        Isomorphic Software

        Comment


          #5
          Thank you for a quick response and identifying and fixing the problem. What about the button issue though? Where the button gets highlighted instead of actually being clicked on? Should I start another thread for this issue?

          Thanks.

          Comment

          Working...
          X