Fluentlenium在play框架中崩溃了jquery

时间:2015-03-05 10:25:00

标签: selenium-webdriver webdriver fluentlenium

我想编写Fluentlenium测试,但它在jQuery上崩溃了。我使用标准集成到play框架中。我试着让简单的标准例子起作用。如果我运行测试,得到(最重要的)

    Caused by: com.gargoylesoftware.htmlunit.ScriptException: TypeError: Cannot find function addEventListener in object [object HTMLDocument]. (http://cg.ch:3333/vassets/lib/jquery/jquery.min.js#2)
Caused by: net.sourceforge.htmlunit.corejs.javascript.EcmaError: TypeError: Cannot find function addEventListener in object [object HTMLDocument]. (http://cg.ch:3333/vassets/lib/jquery/jquery.min.js#2)

我正在使用jQuery v2.1.3。

有什么想法吗?

这是完整的痕迹:

[error] Driver info: driver.version: HtmlUnitDriver, took 6.175 sec
[error]     at org.openqa.selenium.htmlunit.HtmlUnitDriver.get(HtmlUnitDriver.java:484)
[error]     at org.openqa.selenium.htmlunit.HtmlUnitDriver.get(HtmlUnitDriver.java:463)
[error]     at org.fluentlenium.core.Fluent.goTo(Fluent.java:336)
[error]     at IntegrationTest$1.invoke(IntegrationTest.java:22)
[error]     at IntegrationTest$1.invoke(IntegrationTest.java:20)
[error]     at play.test.Helpers.running(Helpers.java:555)
[error]     at play.test.Helpers.running(Helpers.java:541)
[error]     at IntegrationTest.test(IntegrationTest.java:20)
[error]     ...
[error] Caused by: com.gargoylesoftware.htmlunit.ScriptException: TypeError: Cannot find function addEventListener in object [object HTMLDocument]. (http://cg.ch:3333/vassets/lib/jquery/jquery.min.js#2)
[error]     at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:684)
[error]     at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:602)
[error]     at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:507)
[error]     at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.execute(JavaScriptEngine.java:570)
[error]     at com.gargoylesoftware.htmlunit.html.HtmlPage.loadExternalJavaScriptFile(HtmlPage.java:1062)
[error]     at com.gargoylesoftware.htmlunit.html.HtmlScript.executeScriptIfNeeded(HtmlScript.java:409)
[error]     at com.gargoylesoftware.htmlunit.html.HtmlScript$3.execute(HtmlScript.java:266)
[error]     at com.gargoylesoftware.htmlunit.html.HtmlScript.onAllChildrenAddedToPage(HtmlScript.java:286)
[error]     at com.gargoylesoftware.htmlunit.html.HTMLParser$HtmlUnitDOMBuilder.endElement(HTMLParser.java:683)
[error]     at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source)
[error]     at com.gargoylesoftware.htmlunit.html.HTMLParser$HtmlUnitDOMBuilder.endElement(HTMLParser.java:642)
[error]     at org.cyberneko.html.HTMLTagBalancer.callEndElement(HTMLTagBalancer.java:1170)
[error]     at org.cyberneko.html.HTMLTagBalancer.endElement(HTMLTagBalancer.java:1072)
[error]     at org.cyberneko.html.filters.DefaultFilter.endElement(DefaultFilter.java:206)
[error]     at org.cyberneko.html.filters.NamespaceBinder.endElement(NamespaceBinder.java:330)
[error]     at org.cyberneko.html.HTMLScanner$ContentScanner.scanEndElement(HTMLScanner.java:3116)
[error]     at org.cyberneko.html.HTMLScanner$ContentScanner.scan(HTMLScanner.java:2083)
[error]     at org.cyberneko.html.HTMLScanner.scanDocument(HTMLScanner.java:918)
[error]     at org.cyberneko.html.HTMLConfiguration.parse(HTMLConfiguration.java:499)
[error]     at org.cyberneko.html.HTMLConfiguration.parse(HTMLConfiguration.java:452)
[error]     at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
[error]     at com.gargoylesoftware.htmlunit.html.HTMLParser$HtmlUnitDOMBuilder.parse(HTMLParser.java:899)
[error]     at com.gargoylesoftware.htmlunit.html.HTMLParser.parse(HTMLParser.java:242)
[error]     at com.gargoylesoftware.htmlunit.html.HTMLParser.parseHtml(HTMLParser.java:188)
[error]     at com.gargoylesoftware.htmlunit.DefaultPageCreator.createHtmlPage(DefaultPageCreator.java:268)
[error]     at com.gargoylesoftware.htmlunit.DefaultPageCreator.createPage(DefaultPageCreator.java:156)
[error]     at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.java:437)
[error]     at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:311)
[error]     at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:376)
[error]     at org.openqa.selenium.htmlunit.HtmlUnitDriver.get(HtmlUnitDriver.java:474)
[error]     ... 41 more
[error] Caused by: net.sourceforge.htmlunit.corejs.javascript.EcmaError: TypeError: Cannot find function addEventListener in object [object HTMLDocument]. (http://cg.ch:3333/vassets/lib/jquery/jquery.min.js#2)
[error]     at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3603)
[error]     at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3587)
[error]     at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.typeError(ScriptRuntime.java:3608)
[error]     at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.typeError2(ScriptRuntime.java:3624)
[error]     at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.notFunctionError(ScriptRuntime.java:3688)
[error]     at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.getPropFunctionAndThisHelper(ScriptRuntime.java:2207)
[error]     at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.getPropFunctionAndThis(ScriptRuntime.java:2189)
[error]     at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpretLoop(Interpreter.java:1333)
[error]     at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpret(Interpreter.java:798)
[error]     at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.call(InterpretedFunction.java:105)
[error]     at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.doTopCall(ContextFactory.java:405)
[error]     at com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory.doTopCall(HtmlUnitContextFactory.java:309)
[error]     at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3031)
[error]     at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.exec(InterpretedFunction.java:115)
[error]     at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$3.doRun(JavaScriptEngine.java:561)
[error]     at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:669)
[error]     ... 70 more
[error] Failed: Total 2, Failed 1, Errors 0, Passed 1
[error] Failed tests:
[error]     IntegrationTest
[error] (root/test:test) sbt.TestsFailedException: Tests unsuccessful
[error] Total time: 8 s, completed Mar 5, 2015 11:17:06 AM

1 个答案:

答案 0 :(得分:3)

发生错误是因为play.test.Helpers.HTMLUNIT测试浏览器启用了JavaScript并且在jQuery脚本源中发现错误。我发现的唯一解决方法是在测试驱动程序上禁用JavaScript。

所以不要像

那样调用你的测试
running(testServer(3333,fake), HTMLUNIT, new Callback<TestBrowser>() {
    public void invoke(TestBrowser browser) throws JAXBException, IOException {

你应该做

running(testServer(3333,fake), new HtmlUnitDriver(), new Callback<TestBrowser>() {
    public void invoke(TestBrowser browser) throws JAXBException, IOException {

当然,请注意,如果您这样做,您不应期望页面中的JavaScript代码在测试浏览器中执行。