Search code examples
javahttp-unit

Error in HTTPUnit Code


I am trying to learn HTTPUnit and have read cookbook mentioned on http://httpunit.sourceforge.net/doc/cookbook.html

But when I am trying this very simple code

package httpUnit.test;    
import java.io.IOException;
import org.xml.sax.SAXException;
import com.meterware.httpunit.GetMethodWebRequest;
import com.meterware.httpunit.WebConversation;
import com.meterware.httpunit.WebLink;
import com.meterware.httpunit.WebRequest;
import com.meterware.httpunit.WebResponse;

/*** Hello world!**/

public class App{
    public static void main( String[] args ) throws IOException, SAXException {
        System.out.println( "Trying HTPUnit library");
        WebConversation wc = new WebConversation();
        WebRequest req = new GetMethodWebRequest("http://localhost:8080/proof/demo.html");
        WebResponse resp = wc.getResponse(req);

        /* WebLink[ ] link = resp.getLinks();
        for (int i=0; i<link.length; i++) {                                 
            System.out.println(link[i].getText());
        }
        System.out.println(link.length);
        */
    }
};

I am getting the following errors:

TypeError: undefined is not a function. (httpunit; line 15)
at org.mozilla.javascript.NativeGlobal.constructError(NativeGlobal.java:597)
at org.mozilla.javascript.NativeGlobal.constructError(NativeGlobal.java:557)
Error continues.....

and

Exception in thread "main" com.meterware.httpunit.ScriptException: Script '/*!
* jQuery JavaScript Library v1.6
* http://jquery.com/

Can somebody please figure out what could be the problem. I could not understand. I have created the maven project with maven dependency from http://mvnrepository.com/artifact/httpunit/httpunit/1.6.1

And I have hosted demo.html in proof folder in tomcat which is opening fine in browser.


Solution

  • I think the problem is with javascript only.

    Checkout http://httpunit.sourceforge.net/doc/faq.html#javascript

    And use HttpUnitOptions.setScriptingEnabled(false);

    I think it will do.