form is not supmitted

2007-01-19
2013-04-26
  • Hi all and greetings from Munich/Germany!

    I am facing an anoying problem here. I wrote a small HttpUnit class to test
    my website but the submit() has no effect at all. I never reach the
    Welcome page; currentPage is always the login page.
    Does anybody has a hint for me?
    I am running out of ideas... :-/

    My code:
    public void testMailLogin() throws Exception {
          try {
                  WebConversation conversation = new WebConversation();
                WebRequest  request = new GetMethodWebRequest(URL);
                WebResponse response = conversation.getResponse(request);
                assertNotNull("No response from URL '" + URL + "'.", response);
           
                System.out.print("Fetching password login form .........");
             WebForm loginForm = response.getFormWithName("login_Password");
                assertNotNull("No form found with ID 'login_Password'", loginForm);
             System.out.println("OK.");           

            // Fill out auth data and submit login form
                loginForm.setParameter("usr_name", "admin");
                loginForm.setParameter("usr_password", "secret");

                System.out.print("Test presence of login button ........");
                SubmitButton sb = loginForm.getSubmitButton("login");
                assertNotNull("No button found with ID 'login'", sb);
                System.out.println("OK.");   
                response = loginForm.submit(sb);
                assertNotNull("No response after submit of login button", response);
           
                WebResponse selectUserPage = conversation.getCurrentPage();
                   
            System.out.println(selectUserPage.getTitle());
                assertEquals(selectUserPage.getText().indexOf("Welcome") != -1, true);
                System.out.println("OK.");   
        }
        catch (Exception e) {
            System.err.println("Exception: " + e);
        }
       
      } // testMailLogin()

    -----

    my page:

    <form action="?" method="post" name="login_Password" target="_self" autocomplete="off" onsubmit="return isSingleClick()">
    ...
    <input maxlength="255" value="" name="usr_name" type="text" class="textfield " /><br/>
    My password<br/>
    <input maxlength="32" value="" class="textfield " type="password" name="usr_password" /><br/>

    ...

    </form>

     
    • zeyad
      zeyad
      2007-01-20

      Hello sire,
      Your condition is not correct assertEquals(selectUserPage.getText().indexOf("Welcome") != -1, true); because the assertEquals() it can not make assert for  boolean result with character excepted value (true), So I suggest to check your page title in welcome page instead of using this comparison

      With regards

       
      • Hi and thank you for the reply,

        thx for the hint but I still have the problem that
        the login-Form is not submitted.
        selectUserPage.getText() prints always the code of the login
        page, not the expected welcome page :-(

        TIA,
        Andi

         
    • No idea, anyone?

       
    • Jeff
      Jeff
      2007-02-28

      Check this and try something similar:

      http://sourceforge.net/forum/message.php?msg_id=4183243

       
      • *antk43* Thanks 4 the hint!