HttpUnit 和 jQuery:EcmaError

发布于 2024-10-31 07:39:23 字数 4296 浏览 0 评论 0原文

目前我正在为 j2ee 应用程序开发单元测试。 它使用 jQuery 版本 1.4。

当我尝试单击链接并转到下一个网页(在 java 测试代码中)时,HttpUnit 失败并出现异常:

org.mozilla.javascript.EcmaError: TypeError: Cannot find function createElement in object [object Document]. (httpunit#916)
    at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3654)
    at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3632)
    at org.mozilla.javascript.ScriptRuntime.typeError(ScriptRuntime.java:3660)
    at org.mozilla.javascript.ScriptRuntime.typeError2(ScriptRuntime.java:3679)
    at org.mozilla.javascript.ScriptRuntime.notFunctionError(ScriptRuntime.java:3743)
    at org.mozilla.javascript.ScriptRuntime.getPropFunctionAndThisHelper(ScriptRuntime.java:2247)
    at org.mozilla.javascript.ScriptRuntime.getPropFunctionAndThis(ScriptRuntime.java:2214)
    at org.mozilla.javascript.Interpreter.interpretLoop(Interpreter.java:3143)
    at script(httpunit:916)
    at script(httpunit:912)
    at script(httpunit:15)
    at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:2487)
    at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:164)
    at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:398)
    at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3065)
    at org.mozilla.javascript.InterpretedFunction.exec(InterpretedFunction.java:175)
    at org.mozilla.javascript.Context.evaluateString(Context.java:1104)
    at com.meterware.httpunit.javascript.ScriptingEngineImpl.runScript(ScriptingEngineImpl.java:92)
    at com.meterware.httpunit.scripting.ScriptableDelegate.runScript(ScriptableDelegate.java:88)
    at com.meterware.httpunit.ParsedHTML.interpretScriptElement(ParsedHTML.java:364)
    at com.meterware.httpunit.ParsedHTML$ScriptFactory.recordElement(ParsedHTML.java:533)
    at com.meterware.httpunit.ParsedHTML$2.processElement(ParsedHTML.java:744)
    at com.meterware.httpunit.NodeUtils$PreOrderTraversal.perform(NodeUtils.java:241)
    at com.meterware.httpunit.ParsedHTML.loadElements(ParsedHTML.java:760)
    at com.meterware.httpunit.ParsedHTML.getFrames(ParsedHTML.java:1101)
    at com.meterware.httpunit.WebResponse.getFrames(WebResponse.java:1285)
    at com.meterware.httpunit.WebResponse.getFrameRequests(WebResponse.java:1024)
    at com.meterware.httpunit.FrameHolder.updateFrames(FrameHolder.java:179)
    at com.meterware.httpunit.WebWindow.updateFrameContents(WebWindow.java:315)
    at com.meterware.httpunit.WebClient.updateFrameContents(WebClient.java:526)
    at com.meterware.httpunit.WebWindow.updateWindow(WebWindow.java:201)
    at com.meterware.httpunit.WebWindow.getSubframeResponse(WebWindow.java:183)
    at com.meterware.httpunit.WebWindow.getResponse(WebWindow.java:158)
    at com.meterware.httpunit.WebWindow.sendRequest(WebWindow.java:134)
    at com.meterware.httpunit.WebResponse.submitRequest(WebResponse.java:742)
    at com.meterware.httpunit.dom.DomWindow.submitRequest(DomWindow.java:181)
    at com.meterware.httpunit.dom.HTMLAnchorElementImpl.doClickAction(HTMLAnchorElementImpl.java:183)
    at com.meterware.httpunit.WebLink.click(WebLink.java:96)
    at mycompany.testcase.pages.WelcomePage.goToFilterPage(WelcomePage.java:30)
    at mycompany.testcase.DownloadReportTest.testReportDownload(DownloadReportTest.java:16)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at junit.framework.TestCase.runTest(TestCase.java:168)
    at junit.framework.TestCase.runBare(TestCase.java:134)
    at junit.framework.TestResult$1.protect(TestResult.java:110)
    at junit.framework.TestResult.runProtected(TestResult.java:128)
    at junit.framework.TestResult.run(TestResult.java:113)
    at junit.framework.TestCase.run(TestCase.java:124)
    at junit.framework.TestSuite.runTest(TestSuite.java:243)
    at junit.framework.TestSuite.run(TestSuite.java:238)
    at junit.framework.TestSuite.runTest(TestSuite.java:243)
    at junit.framework.TestSuite.run(TestSuite.java:238)
    at mycompany.App.main(App.java:29)

有人知道避免此错误的任何解决方法吗?谢谢 !

Currently I'm developing unit tests for j2ee application.
It uses jQuery version 1.4.

And when I'm trying to click the link and go the next web page(in java test code), HttpUnit fails with exception:

org.mozilla.javascript.EcmaError: TypeError: Cannot find function createElement in object [object Document]. (httpunit#916)
    at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3654)
    at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3632)
    at org.mozilla.javascript.ScriptRuntime.typeError(ScriptRuntime.java:3660)
    at org.mozilla.javascript.ScriptRuntime.typeError2(ScriptRuntime.java:3679)
    at org.mozilla.javascript.ScriptRuntime.notFunctionError(ScriptRuntime.java:3743)
    at org.mozilla.javascript.ScriptRuntime.getPropFunctionAndThisHelper(ScriptRuntime.java:2247)
    at org.mozilla.javascript.ScriptRuntime.getPropFunctionAndThis(ScriptRuntime.java:2214)
    at org.mozilla.javascript.Interpreter.interpretLoop(Interpreter.java:3143)
    at script(httpunit:916)
    at script(httpunit:912)
    at script(httpunit:15)
    at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:2487)
    at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:164)
    at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:398)
    at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3065)
    at org.mozilla.javascript.InterpretedFunction.exec(InterpretedFunction.java:175)
    at org.mozilla.javascript.Context.evaluateString(Context.java:1104)
    at com.meterware.httpunit.javascript.ScriptingEngineImpl.runScript(ScriptingEngineImpl.java:92)
    at com.meterware.httpunit.scripting.ScriptableDelegate.runScript(ScriptableDelegate.java:88)
    at com.meterware.httpunit.ParsedHTML.interpretScriptElement(ParsedHTML.java:364)
    at com.meterware.httpunit.ParsedHTML$ScriptFactory.recordElement(ParsedHTML.java:533)
    at com.meterware.httpunit.ParsedHTML$2.processElement(ParsedHTML.java:744)
    at com.meterware.httpunit.NodeUtils$PreOrderTraversal.perform(NodeUtils.java:241)
    at com.meterware.httpunit.ParsedHTML.loadElements(ParsedHTML.java:760)
    at com.meterware.httpunit.ParsedHTML.getFrames(ParsedHTML.java:1101)
    at com.meterware.httpunit.WebResponse.getFrames(WebResponse.java:1285)
    at com.meterware.httpunit.WebResponse.getFrameRequests(WebResponse.java:1024)
    at com.meterware.httpunit.FrameHolder.updateFrames(FrameHolder.java:179)
    at com.meterware.httpunit.WebWindow.updateFrameContents(WebWindow.java:315)
    at com.meterware.httpunit.WebClient.updateFrameContents(WebClient.java:526)
    at com.meterware.httpunit.WebWindow.updateWindow(WebWindow.java:201)
    at com.meterware.httpunit.WebWindow.getSubframeResponse(WebWindow.java:183)
    at com.meterware.httpunit.WebWindow.getResponse(WebWindow.java:158)
    at com.meterware.httpunit.WebWindow.sendRequest(WebWindow.java:134)
    at com.meterware.httpunit.WebResponse.submitRequest(WebResponse.java:742)
    at com.meterware.httpunit.dom.DomWindow.submitRequest(DomWindow.java:181)
    at com.meterware.httpunit.dom.HTMLAnchorElementImpl.doClickAction(HTMLAnchorElementImpl.java:183)
    at com.meterware.httpunit.WebLink.click(WebLink.java:96)
    at mycompany.testcase.pages.WelcomePage.goToFilterPage(WelcomePage.java:30)
    at mycompany.testcase.DownloadReportTest.testReportDownload(DownloadReportTest.java:16)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at junit.framework.TestCase.runTest(TestCase.java:168)
    at junit.framework.TestCase.runBare(TestCase.java:134)
    at junit.framework.TestResult$1.protect(TestResult.java:110)
    at junit.framework.TestResult.runProtected(TestResult.java:128)
    at junit.framework.TestResult.run(TestResult.java:113)
    at junit.framework.TestCase.run(TestCase.java:124)
    at junit.framework.TestSuite.runTest(TestSuite.java:243)
    at junit.framework.TestSuite.run(TestSuite.java:238)
    at junit.framework.TestSuite.runTest(TestSuite.java:243)
    at junit.framework.TestSuite.run(TestSuite.java:238)
    at mycompany.App.main(App.java:29)

Does anybody knows any workaround to avoid this error ? Thanks !

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

扶醉桌前 2024-11-07 07:39:23

作为解决方法,我建议禁用 Javascript:

HttpUnitOptions.setScriptingEnabled(false);

As a workaround I would recomment disabling Javascript:

HttpUnitOptions.setScriptingEnabled(false);
一念一轮回 2024-11-07 07:39:23

我发现的唯一方法是拒绝使用 HttpUnit 并在 jWebUnitHtmlUnit

The only way I've found is to refuse using HttpUnit and choose between jWebUnit and HtmlUnit

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文