httpUnit

T

Tom Koenning

I am trying to use httpUnit/junit to test the login on our website.
The following is the test case I am trying to run on my localhost:

import com.meterware.httpunit.*;
import com.meterware.servletunit.*;
import junit.framework.*;

public class HttpUnitTest extends TestCase {
private String url;

public HttpUnitTest(String name) {
super(name);
}

public static void main( String args[] ) {
junit.textui.TestRunner.run( suite() );
}

public static TestSuite suite() {
return new TestSuite( HttpUnitTest.class );
}


public void setUp() {
//url = "http://quartz:9080/msis/UserLoginForm";
//url = "https://limestone.msha.gov/msis/UserLoginForm";
url = "http://localhost:7001/msis/UserLoginForm";
HttpUnitOptions.setExceptionsThrownOnErrorStatus(true);
HttpUnitOptions.setMatchesIgnoreCase(true);
//HttpUnitOptions.setParserWarningsEnabled(true);
}
/*
public void testGetLoginForm() throws Exception {
WebConversation session = new WebConversation();
WebRequest request = new GetMethodWebRequest(url);
WebResponse response = session.getResponse(request);
assertEquals("User Login", response.getTitle());
//assertEquals("Ralph", response.getTitle());
}
*/
public void testLogin() throws Exception {
WebConversation session = new WebConversation();
WebRequest request = new GetMethodWebRequest(url);
WebResponse response = session.getResponse(request);
WebForm form = response.getForms()[0];
assertEquals("",form.getParameterValue("userId"));
form.setParameter("userId","a user");
form.setParameter("password","password");
form.submit();
response = session.getCurrentPage();
/assertEquals("Welcome Page", response.getTitle());
System.out.println("response from login attempt is: " +
response.toString());
assertEquals( "Page title", "Welcome Page", response.getTitle() );
}

}

The test that has been commented out "testGetLoginForm()" works fine.
When I try the test "testLogin()" I get some errors as follows:

There was 1 error:
1) testLogin(HttpUnitTest)[Loaded java.lang.StackTraceElement from
C:\Program Files\Java\j2re1.4.1_0
1\lib\rt.jar]
java.lang.NoSuchMethodError:
org.apache.xerces.xni.Augmentations.clear()V
at org.cyberneko.html.HTMLScanner.locationAugs(Unknown Source)
at org.cyberneko.html.HTMLScanner$ContentScanner.scan(Unknown
Source)
at org.cyberneko.html.HTMLScanner.scanDocument(Unknown Source)
at org.cyberneko.html.HTMLConfiguration.parse(Unknown Source)
at org.cyberneko.html.HTMLConfiguration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
at com.meterware.httpunit.parsing.NekoHTMLParser.parse(NekoHTMLParser.java:41)
at com.meterware.httpunit.HTMLPage.parse(HTMLPage.java:244)
at com.meterware.httpunit.WebResponse.getReceivedPage(WebResponse.java:975)
at com.meterware.httpunit.WebResponse$Scriptable.load(WebResponse.java:577)
at com.meterware.httpunit.javascript.JavaScript$Window.initialize(JavaScript.java:419)
at com.meterware.httpunit.javascript.JavaScript.run(JavaScript.java:80)
at com.meterware.httpunit.javascript.JavaScriptEngineFactory.associate(JavaScriptEngineFacto
ry.java:46)
at com.meterware.httpunit.FrameHolder.<init>(FrameHolder.java:44)
at com.meterware.httpunit.WebWindow.<init>(WebWindow.java:218)
at com.meterware.httpunit.WebClient.<init>(WebClient.java:51)
at com.meterware.httpunit.WebConversation.<init>(WebConversation.java:46)
at HttpUnitTest.testLogin(HttpUnitTest.java:39)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at HttpUnitTest.main(HttpUnitTest.java:13)

FAILURES!!!
Tests run: 1, Failures: 0, Errors: 1

[Loaded java.util.HashMap$KeyIterator from C:\Program
Files\Java\j2re1.4.1_01\lib\rt.jar]

Any thoughts?

Thanks, Tom K
 
T

Tom Koenning

I am trying to use httpUnit/junit to test the login on our website.
The following is the test case I am trying to run on my localhost:

import com.meterware.httpunit.*;
import com.meterware.servletunit.*;
import junit.framework.*;

public class HttpUnitTest extends TestCase {
private String url;

public HttpUnitTest(String name) {
super(name);
}

public static void main( String args[] ) {
junit.textui.TestRunner.run( suite() );
}

public static TestSuite suite() {
return new TestSuite( HttpUnitTest.class );
}


public void setUp() {
//url = "http://quartz:9080/msis/UserLoginForm";
//url = "https://limestone.msha.gov/msis/UserLoginForm";
url = "http://localhost:7001/msis/UserLoginForm";
HttpUnitOptions.setExceptionsThrownOnErrorStatus(true);
HttpUnitOptions.setMatchesIgnoreCase(true);
//HttpUnitOptions.setParserWarningsEnabled(true);
}
/*
public void testGetLoginForm() throws Exception {
WebConversation session = new WebConversation();
WebRequest request = new GetMethodWebRequest(url);
WebResponse response = session.getResponse(request);
assertEquals("User Login", response.getTitle());
//assertEquals("Ralph", response.getTitle());
}
*/
public void testLogin() throws Exception {
WebConversation session = new WebConversation();
WebRequest request = new GetMethodWebRequest(url);
WebResponse response = session.getResponse(request);
WebForm form = response.getForms()[0];
assertEquals("",form.getParameterValue("userId"));
form.setParameter("userId","a user");
form.setParameter("password","password");
form.submit();
response = session.getCurrentPage();
/assertEquals("Welcome Page", response.getTitle());
System.out.println("response from login attempt is: " +
response.toString());
assertEquals( "Page title", "Welcome Page", response.getTitle() );
}

}

The test that has been commented out "testGetLoginForm()" works fine.
When I try the test "testLogin()" I get some errors as follows:

There was 1 error:
1) testLogin(HttpUnitTest)[Loaded java.lang.StackTraceElement from
C:\Program Files\Java\j2re1.4.1_0
1\lib\rt.jar]
java.lang.NoSuchMethodError:
org.apache.xerces.xni.Augmentations.clear()V
at org.cyberneko.html.HTMLScanner.locationAugs(Unknown Source)
at org.cyberneko.html.HTMLScanner$ContentScanner.scan(Unknown
Source)
at org.cyberneko.html.HTMLScanner.scanDocument(Unknown Source)
at org.cyberneko.html.HTMLConfiguration.parse(Unknown Source)
at org.cyberneko.html.HTMLConfiguration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
at com.meterware.httpunit.parsing.NekoHTMLParser.parse(NekoHTMLParser.java:41)
at com.meterware.httpunit.HTMLPage.parse(HTMLPage.java:244)
at com.meterware.httpunit.WebResponse.getReceivedPage(WebResponse.java:975)
at com.meterware.httpunit.WebResponse$Scriptable.load(WebResponse.java:577)
at com.meterware.httpunit.javascript.JavaScript$Window.initialize(JavaScript.java:419)
at com.meterware.httpunit.javascript.JavaScript.run(JavaScript.java:80)
at com.meterware.httpunit.javascript.JavaScriptEngineFactory.associate(JavaScriptEngineFacto
ry.java:46)
at com.meterware.httpunit.FrameHolder.<init>(FrameHolder.java:44)
at com.meterware.httpunit.WebWindow.<init>(WebWindow.java:218)
at com.meterware.httpunit.WebClient.<init>(WebClient.java:51)
at com.meterware.httpunit.WebConversation.<init>(WebConversation.java:46)
at HttpUnitTest.testLogin(HttpUnitTest.java:39)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at HttpUnitTest.main(HttpUnitTest.java:13)

FAILURES!!!
Tests run: 1, Failures: 0, Errors: 1

[Loaded java.util.HashMap$KeyIterator from C:\Program
Files\Java\j2re1.4.1_01\lib\rt.jar]

Any thoughts?

Thanks, Tom K

Russell: Thanks for your help, but unfortunately when I followed your
suggestion to use the setAuthorization("usid","pw") method I am still
getting the same error.

Thanks, Tom K
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top