3 Replies Latest reply on Jan 2, 2007 4:27 PM by 796447

    HttpUnit Testing error

      Hi all,

      HAPPY NEW YEAR to every one.

      i have one problem in HttpUnit, i used below code to login the page, i entered same un and password directly in IE login is working, but in HttpUnit below program not login, another method testContactUs Link click is working properly.


      import com.meterware.httpunit.*;
      import junit.framework.*;
      import java.net.*;
      import java.io.*;
      import java.util.*;
      import junit.framework.TestCase;
      public class TestHttpUnitTest extends TestCase {
          public static void main(String[] args) {
          public TestHttpUnitTest(String name) {
      public static void testLogin() throws Exception {
              WebConversation wc = new WebConversation();
              WebRequest request = new GetMethodWebRequest("http://localhost:7001/project/flow.jx?stateID=start");
              WebResponse response = wc.getResponse(request);
              WebForm loginForm = response.getForms()[0];
              request = loginForm.getRequest();
              request.setParameter("userID", "password");
              request.setParameter("tempID", "tempPASS");
              response = loginForm.submit();
              //response = wc.getResponse(request);
              assertTrue("Login rejected while logging in with 'tempID'",
                      response.getText().indexOf("Invalid Username or Password") != -1);
              String text = response.getText();
              System.out.println("Login Response:" + text);
       public static void testContactUsClick() throws Exception {
              WebConversation wc = new WebConversation(); // create a new web client
              WebResponse response = wc.getResponse( "http://localhost:7001/project/index.html" ); //get the response from Web Server
              response = response.getLinkWith("contact us").click();
              System.out.println("The title of the ContactUs page is: " + response.getTitle());
        • 1. Re: HttpUnit Testing error
          request.setParameter("userID", "password");
          request.setParameter("tempID", "tempPASS");
          Maybe you're just guessing at the query parameters that the login form expects. Have you actually examined the HTML source of the login form, to ensure you are setting up posting the correct parameter names and values to it?
          • 2. Re: HttpUnit Testing error
            Yes my friend, i check the code and put the exact parameter names.
            • 3. Re: HttpUnit Testing error
              So the password is passed to a field named "tempID"? That's odd. The next step might be to make sure your code is grabbing the right form.
              You're doing this:
              WebForm loginForm = response.getForms()[0];
              Are you sure that is returning the one you think it is? You should do some debugging (using a real debugger to step thru the code and examine things, or use a "poor man's debugger" by simply adding some System.out.println statements in there to let it show you what form the code actually retrieved).