• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

HttpUnit Help..

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can Anyone please find, what is the problem with this code..
/*
* This is to test JSP using HttpUnit
*
*/
package test;
//import org.apache.cactus.*;
//import org.apache.cactus.ServletTestCase.*;
import junit.framework.*;
import com.meterware.httpunit.*;

public class TestEvalIt extends TestCase
{
public static void main(String args[])
{
junit.textui.TestRunner.run( suite() );
}
public static Test suite()
{
return new TestSuite( TestEvalIt.class );
}
public TestEvalIt( String name )
{
super( name);
}
/* Testing the EvalIt has only one form
*/
public void testViewEvalITPage() throws Exception
{
WebConversation conversation = new WebConversation();
WebRequest request = new GetMethodWebRequest( "http://localhost:8080/NDIC/ViewEvalIT.jsp" );
WebResponse response = conversation.getResponse( request );
WebForm forms[] = response.getForms();
assertEquals( 1, forms.length );
assertEquals( 1, forms[0].getParameterNames().length );
assertEquals( "name", forms[0].getParameterNames()[0] );
}
}
Its giving me the following error
.Rhino classes (js.jar) not found - Javascript disabled
at java.lang.ClassLoader.loadClass(ClassLoader.java:262)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:322)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:130)
at com.meterware.httpunit.parsing.HTMLParserFactory.loadParserIfSupporte
d(HTMLParserFactory.java:182)
at com.meterware.httpunit.parsing.HTMLParserFactory.<clinit>(HTMLParserF
actory.java:194)
at com.meterware.httpunit.HTMLPage.parse(HTMLPage.java:244)
at com.meterware.httpunit.WebResponse.getReceivedPage(WebResponse.java:9
75)
at com.meterware.httpunit.WebResponse.getForms(WebResponse.java:295)
at test.TestEvalIt.testViewEvalITPage(TestEvalIt.java:35)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
at test.TestEvalIt.main(TestEvalIt.java:17)
FAILURES!!!
Tests run: 1, Failures: 0, Errors: 1
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does the JSP's output contain JavaScript?
Would it be possible to just add js.jar into your classpath?
 
Pramoda Bhat
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've added js.jar in the classpath!!
 
Pramoda Bhat
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Intially I had not added js.jar in my classpath.. I'm getting below mentioned error after adding the js.jar in my classpath
1) testViewEvalITPage(test.EvalItTest)java.lang.NoClassDefFoundError: org/apache
/xerces/util/ParserConfigurationSettings
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:509)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:12
3)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:246)
at java.net.URLClassLoader.access$100(URLClassLoader.java:54)
at java.net.URLClassLoader$1.run(URLClassLoader.java:193)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:186)
at java.lang.ClassLoader.loadClass(ClassLoade
at com.meterware.httpunit.WebConversation.<init>(WebConversation.java:46
)
at test.EvalItTest.testViewEvalITPage(EvalItTest.java:31)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
at test.EvalItTest.main(EvalItTest.java:17)
2) testViewEvalITPageTitle(test.EvalItTest)java.lang.NoClassDefFoundError
at com.meterware.httpunit.HTMLPage.parse(HTMLPage.java:244)
at com.meterware.httpunit.WebResponse.getReceivedPage(WebResponse.java:9
75)
at com.meterware.httpunit.WebResponse$Scriptable.load(WebResponse.java:5
77)
at com.meterware.httpunit.javascript.JavaScript$Window.initialize(JavaSc
ript.java:419)
at com.meterware.httpunit.javascript.JavaScript.run(JavaScript.java:80)
at com.meterware.httpunit.javascript.JavaScriptEngineFactory.associate(J
avaScriptEngineFactory.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
)
......
...
..
..
Is it something to do with xerces.jar I have in my classpath?
 
Ranch Hand
Posts: 8946
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Lasse,
Will javascript create problems?
 
Lasse Koskela
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Will javascript create problems?

No, it shouldn't create problems. I just thought that it might be the cause for the exception if the page contains JavaScript but HttpUnit can't find the js.jar...

testViewEvalITPage(test.EvalItTest)java.lang.NoClassDefFoundError: org/apache/xerces/util/ParserConfigurationSettings

Take a look inside your xerces.jar and see if it contains this class.
 
Pramoda Bhat
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you, That class wasn't there in the xerces.jar
But then.. my problem is not solved yet!!!
I'm getting new errors...
------Here is the code..-----
package test;
import junit.framework.*;
import com.meterware.httpunit.*;

public class EvalItTest extends TestCase
{
public static void main(String args[])
{
junit.textui.TestRunner.run( suite() );
}
public static Test suite()
{
return new TestSuite( EvalItTest.class );
}
public EvalItTest( String name )
{
super( name);
}
/* Testing the EvalIt has only one form
*/
public void testViewEvalITPage() throws Exception
{
WebConversation conversation = new WebConversation();
WebRequest request = new GetMethodWebRequest("http://localhost:8080/NDIC/login.htm" );
WebResponse response = conversation.getResponse(request);
WebForm forms[] = response.getForms();
assertEquals( 1, forms.length );
assertEquals( 1, forms[0].getParameterNames().length );
assertEquals( "name", forms[0].getParameterNames()[0] );
}
}
----- code end ------
Here is the error...
There was 1 error:
1) testViewEvalITPage(test.EvalItTest)java.lang.RuntimeException: java.lang.reflect.InvocationTargetException at com.meterware.httpunit.javascript.JavaScriptEngineFactory.associate(J
avaScriptEngineFactory.java:51)
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 test.EvalItTest.testViewEvalITPage(EvalItTest.java:31)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
at test.EvalItTest.main(EvalItTest.java:17)
-- Error ends here --
I've pointed the classpath to the js.jar I got when I downloaded HttpUnit..
 
Lasse Koskela
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No idea. This might be a long shot, but could you post the complete classpath variable? Maybe there are some entries that conflict each other or something.
 
Pramoda Bhat
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is the classpath
SET CLASSPATH=;.;
C:\tomcat\common\lib\servlet.jar;
c:\j2sdk1.4.0\src.jar;
c:\j2sdk1.4.0\lib\dt.jar;
c:\j2sdk1.4.0\lib\tools.jar;
c:\j2sdk1.4.0\lib\j2sdk.jar;
C:\tomcat\webapps\struts-blank\WEB-INF\lib\struts.jar;
C:\tomcat\common\lib\servlet.jar;
C:\tomcat\common\lib\httpunit-1.5.3.jar;
C:\tomcat\common\lib\cactus-ant-1.5-rc1.jar;
C:\tomcat\common\lib\aspectjrt-1.1.1.jar;
C:\tomcat\common\lib\nekohtml-0.7.4.jar;
C:\tomcat\common\lib\servletapi-2.3.jar;
C:\tomcat\common\lib\junit-3.8.1.jar;
c:\tomcat\common\lib\commons-logging-1.0.3.jar;
c:\tomcat\common\lib\commons-httpclient-2.0-rc2.jar;
C:\tomcat\common\lib\cactus-1.5-rc1.jar;
C:\tomcat\common\lib\js.jar;
C:\tomcat\common\lib\xercesImpl.jar;
C:\tomcat\common\lib\xmlParserAPIs.jar;
C:\tomcat\common\lib\activation.jar;
C:\tomcat\common\lib\Tidy.jar;

EDIT: I added linebreaks to avoid the stretched view...
[ November 07, 2003: Message edited by: Lasse Koskela ]
 
Author
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think your best bet is to post your question on the httpunit mailing list...
 
Pramoda Bhat
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have posted the question in HttpUnit mailing list..
at http://sourceforge.net/tracker
but I've not got any Reply
Can anyone please tell me what's wrong with this piece of code..
package test;
import junit.framework.*;
import com.meterware.httpunit.*;
public class EvalItTest extends TestCase
{
public static void main(String args[])
{
junit.textui.TestRunner.run( suite() );
//testViewEvalITPage();
//suite();
}
public static Test suite()
{
return new TestSuite(EvalItTest.class);
}
public EvalItTest( String name )
{
super( name);
}
/* Testing the EvalIt has only one form
*/
public void testViewEvalITPage() throws Exception
{
System.out.println("In testEvalItPage method");
WebConversation conversation = new WebConversation();

System.out.println("*************In testEvalItPage method after conversing**********");
WebRequest request = new GetMethodWebRequest("http://localhost:8080/NDIC/login.htm" );
WebResponse response = conversation.getResponse(request);
WebForm forms[] = response.getForms();
assertEquals( 1, forms.length );
assertEquals( 1, forms[0].getParameterNames().length );
assertEquals( "name", forms[0].getParameterNames()[0] );
}
}
Why is it giving me the below mentioned error..
java.lang.reflect.InvocationTargetException
at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
at com.meterware.httpunit.parsing.NekoHTMLParser.parse(NekoHTMLParser.ja
va:41)
at com.meterware.httpunit.HTMLPage.parse(HTMLPage.java:244)
at com.meterware.httpunit.WebResponse.getReceivedPage(WebResponse.java:9
75)
at com.meterware.httpunit.WebResponse$Scriptable.load(WebResponse.java:5
77)
at com.meterware.httpunit.javascript.JavaScript$Window.initialize(JavaSc
ript.java:419)
at com.meterware.httpunit.javascript.JavaScript.run(JavaScript.java:80)
at com.meterware.httpunit.javascript.JavaScriptEngineFactory.associate(J
avaScriptEngineFactory.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 test.EvalItTest.testViewEvalITPage(EvalItTest.java:31)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at junit.textui.TestRunner.doRun(TestRunner.java:116)
at junit.textui.TestRunner.doRun(TestRunner.java:109)
at junit.textui.TestRunner.run(TestRunner.java:72)
at test.EvalItTest.main(EvalItTest.java:17)
E
There was 1 error:
1) testViewEvalITPage(test.EvalItTest)java.lang.RuntimeException: java.lang.refl
ect.InvocationTargetException
at com.meterware.httpunit.javascript.JavaScriptEngineFactory.associate(J
avaScriptEngineFactory.java:51)
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 test.EvalItTest.testViewEvalITPage(EvalItTest.java:35)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
at test.EvalItTest.main(EvalItTest.java:17)
FAILURES!!!
Tests run: 1, Failures: 0, Errors: 1
 
Lasse Koskela
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could this help?
 
Pramoda Bhat
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, but it didn't work same error..
My God.. how to solve this...
 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you have both JTidy and Neko in your classpath? JTidy is much more strict as to valid HTML. I see that the exception is coming from Neko and what I can I remember, the default is to use Neko and if it isn't in the classpath, then it looks for JTidy. I might try to do the following:
1) Take out JTidy from your classpath and run the test.
2) Take out js.jar from your classpath and run the test. HttpUnit doesn't care if it is in there. If js.jar is in the classpath then JavaScript is enabled, otherwise it doesn't care.
3) If you are still having problems, then I try connecting to a different page that has VERY simple VALID HTML and try again.
If you still have problems, try posting what exactly you did, the VERY SIMPLE HTML you tried to retrieve and which of these steps you tried.
[ November 12, 2003: Message edited by: Christian Hargraves ]
 
Pramoda Bhat
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot..
I was busy with some other assignment so couldn't try what you asked me to do earlier..
I removed jTidy.jar from my classpath still I get the error..
---- My Classpath Looks Like this now ---------
C:\tomcat\common\lib\servlet.jar;
c:\j2sdk1.4.0\src.jar;c:\j2sdk1.4.0\lib\dt.jar;
c:\j2sdk1.4.0\lib\tools.jar;
c:\j2sdk1.4.0\lib\j2sdk.jar;
C:\tomcat\webapps\NDIC\WEB-INF\lib\struts.jar;
C:\tomcat\common\lib\httpunit-1.5.3.jar;
C:\tomcat\common\lib\aspectjrt-1.1.1.jar;
C:\tomcat\common\lib\nekohtml.jar;
C:\tomcat\common\lib\servletapi-2.3.jar;
C:\tomcat\common\lib\junit-3.8.1.jar;
c:\tomcat\common\lib\commons-httpclient-2.0-rc2.jar;
C:\tomcat\common\lib\js.jar;
C:\tomcat\common\lib\xercesImpl.jar;
C:\tomcat\common\lib\xmlParserAPIs.jar;
C:\tomcat\common\lib\activation.jar;
C:\tomcat\common\lib\cactus-1.5-rc1.jar;
C:\tomcat\common\lib\cactus-ant-1.5-rc1.jar;
C:\tomcat\common\lib\commons-logging-1.0.3.jar;
-------Classpath ends here ----------
----Here is my login.htm ---
<html>
<head>
<title>eBAS-Banking Application Systems</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript1.2">
function onLogin()
{
window.open("main.htm","Main","menubar=0,toolbar=0,location=0,directories=0,status=1,scrollbars=1,resizable=1,height=550,width=800,top=0,left=0" );
window.close();
}
</script>
</head>
<link href="cssStyle/Style.css" type="text/css" rel="stylesheet">
<body bgcolor="#F1F1F1" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<form name="theForm">
<table width="100%" border="0" cellspacing="0" cellpadding="0" height="59" bgcolor="003399">
<tr>
<td width="180"><img src="images/logo_1.gif" width="139" height="59"></td>
<td>
<div align="center"><img src="images/ebas2.gif" width="211" height="59"></div>
</td>
<td width="190" align="right">  </td>
</tr>
</table>
</html>
--------- login.htm ends here..--------------------
---------- My Test Case ----------------
package test;
import org.apache.cactus.*;
import org.apache.cactus.ServletTestCase.*;
import junit.framework.*;
import com.meterware.httpunit.*;

public class TestSampleTag extends JspTestCase
{
public static void main( String[] params)
{
try
{
WebConversation wc = new WebConversation();
com.meterware.httpunit.WebResponse response = wc.getResponse("http://localhost:8080/NDIC/login.htm");
TestSampleTag testobj= new TestSampleTag();
testobj.endLogin(response);
}
catch (Exception e)
{
System.err.println( "Exception: " + e );
}
}
public void endLogin(com.meterware.httpunit.WebResponse
response) throws org.xml.sax.SAXException
{
WebTable table = response.getTables()[0];
assertEquals("rows", 1, table.getRowCount());
assertEquals("columns", 3, table.getColumnCount());
assertEquals("links", 1, table.getTableCell(0, 2).getLinks().length);
}
}
------------- Test case ends here-------------------
What could be the problem? It compiles fine.. but while running the test case I get the following error
-------Error---------
C:\tomcat\webapps\NDIC\WEB-INF\classes\test>java test.TestSampleTag
java.lang.reflect.InvocationTargetException
at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
at com.meterware.httpunit.parsing.NekoHTMLParser.parse(NekoHTMLParser.ja
va:41)
at com.meterware.httpunit.HTMLPage.parse(HTMLPage.java:244)
at com.meterware.httpunit.WebResponse.getReceivedPage(WebResponse.java:9
75)
at com.meterware.httpunit.WebResponse$Scriptable.load(WebResponse.java:5
77)
at com.meterware.httpunit.javascript.JavaScript$Window.initialize(JavaSc
ript.java:419)
at com.meterware.httpunit.javascript.JavaScript.run(JavaScript.java:80)
at com.meterware.httpunit.javascript.JavaScriptEngineFactory.associate(J
avaScriptEngineFactory.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 test.TestSampleTag.main(TestSampleTag.java:15)
Exception: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
------------- End error -------
What could be the problem???
 
So you made a portal in time and started grabbing people. This tiny ad thinks that's rude:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic