【问题标题】:Error in HTTPUnit CodeHTTPUnit 代码中的错误
【发布时间】:2012-09-10 08:54:44
【问题描述】:

我正在尝试学习 HTTPUnit,并阅读了 http://httpunit.sourceforge.net/doc/cookbook.html 中提到的食谱

但是当我尝试这个非常简单的代码时

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);
        */
    }
};

我收到以下错误:

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.....

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

有人可以找出可能是什么问题。我无法理解。我已经创建了具有来自http://mvnrepository.com/artifact/httpunit/httpunit/1.6.1 的 maven 依赖项的 maven 项目

我在tomcat的proof文件夹中托管了demo.html,它在浏览器中可以正常打开。

【问题讨论】:

  • PS:我没有发布完整的错误,因为它会增加问题的长度。如果有人说,我会
  • 是不是因为HTML页面也有一些javascript代码??

标签: java http-unit


【解决方案1】:

我认为问题仅出在 javascript 上。

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

并使用 HttpUnitOptions.setScriptingEnabled(false);

我觉得可以。

【讨论】:

  • 非常感谢。你猜对了问题。不支持所有 javascript 构造。再次感谢:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-10-20
  • 1970-01-01
  • 1970-01-01
  • 2012-06-10
  • 2011-02-08
相关资源
最近更新 更多