user3250428
user3250428

Reputation: 1

Geb Tests for pages with javascript in grails 2.3.5

I am upgrading from grails 2.2.4 to grails 2.3.5 and the last problem I am having is with geb functional tests. I have upgraded geb to 0.9.2.

The first problem is that it seems like it is first trying to run the geb tests as spock tests even though there aren't any geb spock tests, before running as a regular geb test.

The second problem is that in both cases when javascript is enabled, i.e. in GebConfig.groovy

driver = {
   def driver = new HtmlUnitDriver()
   driver.javascriptEnabled = true
    return driver

} 

I get the following exception :

|  ======= EXCEPTION START ========
Exception class=[net.sourceforge.htmlunit.corejs.javascript.EvaluatorException]
com.gargoylesoftware.htmlunit.ScriptException: syntax error (http://localhost:8081/xyz/static/IKfETRJERwBRdVMGxGDGgTIvzB2B464w7472lQKpd3b.js#156)
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:684)
    at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:602)
    at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:507)
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.compile(JavaScriptEngine.java:524)
    at com.gargoylesoftware.htmlunit.html.HtmlPage.loadJavaScriptFromUrl(HtmlPage.java:1144)
    at com.gargoylesoftware.htmlunit.html.HtmlPage.loadExternalJavaScriptFile(HtmlPage.java:1039)
    at com.gargoylesoftware.htmlunit.html.HtmlScript.executeScriptIfNeeded(HtmlScript.java:409)
    at com.gargoylesoftware.htmlunit.html.HtmlScript$3.execute(HtmlScript.java:266)
    at com.gargoylesoftware.htmlunit.html.HtmlScript.onAllChildrenAddedToPage(HtmlScript.java:286)
    at com.gargoylesoftware.htmlunit.html.HTMLParser$HtmlUnitDOMBuilder.endElement(HTMLParser.java:683)
    at com.gargoylesoftware.htmlunit.html.HTMLParser$HtmlUnitDOMBuilder.endElement(HTMLParser.java:642)
    at org.cyberneko.html.HTMLTagBalancer.callEndElement(HTMLTagBalancer.java:1170)
    at org.cyberneko.html.HTMLTagBalancer.endElement(HTMLTagBalancer.java:1072)
    at org.cyberneko.html.filters.DefaultFilter.endElement(DefaultFilter.java:206)
    at org.cyberneko.html.filters.NamespaceBinder.endElement(NamespaceBinder.java:330)
    at org.cyberneko.html.HTMLScanner$ContentScanner.scanEndElement(HTMLScanner.java:3116)
    at org.cyberneko.html.HTMLScanner$ContentScanner.scan(HTMLScanner.java:2083)
    at org.cyberneko.html.HTMLScanner.scanDocument(HTMLScanner.java:918)
    at org.cyberneko.html.HTMLConfiguration.parse(HTMLConfiguration.java:499)
    at org.cyberneko.html.HTMLConfiguration.parse(HTMLConfiguration.java:452)
    at com.gargoylesoftware.htmlunit.html.HTMLParser$HtmlUnitDOMBuilder.parse(HTMLParser.java:899)
    at com.gargoylesoftware.htmlunit.html.HTMLParser.parse(HTMLParser.java:242)
    at com.gargoylesoftware.htmlunit.html.HTMLParser.parseHtml(HTMLParser.java:188)
    at com.gargoylesoftware.htmlunit.DefaultPageCreator.createHtmlPage(DefaultPageCreator.java:268)
    at com.gargoylesoftware.htmlunit.DefaultPageCreator.createPage(DefaultPageCreator.java:156)
    at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.java:437)
    at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:311)
    at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:393)
    at com.gargoylesoftware.htmlunit.html.HtmlPage.refresh(HtmlPage.java:2234)
    at org.openqa.selenium.htmlunit.HtmlUnitDriver$HtmlUnitNavigation.refresh(HtmlUnitDriver.java:1282)
    at geb.Browser.go(Browser.groovy:395)
    at geb.Page.to(Page.groovy:184)
    at geb.Browser.via(Browser.groovy:475)
    at geb.Browser.to(Browser.groovy:434)
    at geb.Browser.to(Browser.groovy:412)
    at geb.junit4.GebTest.methodMissing(GebTest.groovy:52)
    ......
 Caused by: net.sourceforge.htmlunit.corejs.javascript.EvaluatorException: syntax error (http://localhost:8081/xyz/static/IKfETRJERwBRdVMGxGDGgTIvzB2B464w7472lQKpd3b.js#156)
    at com.gargoylesoftware.htmlunit.javascript.StrictErrorReporter.error(StrictErrorReporter.java:64)
    at net.sourceforge.htmlunit.corejs.javascript.Parser.addError(Parser.java:187)
    at net.sourceforge.htmlunit.corejs.javascript.Parser.addError(Parser.java:167)
    at net.sourceforge.htmlunit.corejs.javascript.Parser.reportError(Parser.java:219)
    at net.sourceforge.htmlunit.corejs.javascript.Parser.reportError(Parser.java:214)
    at net.sourceforge.htmlunit.corejs.javascript.Parser.mustMatchToken(Parser.java:366)
    at net.sourceforge.htmlunit.corejs.javascript.Parser.mustMatchToken(Parser.java:357)
    at net.sourceforge.htmlunit.corejs.javascript.Parser.xmlInitializer(Parser.java:2292)
    at net.sourceforge.htmlunit.corejs.javascript.Parser.unaryExpr(Parser.java:2252)
    at net.sourceforge.htmlunit.corejs.javascript.Parser.mulExpr(Parser.java:2184)
    at net.sourceforge.htmlunit.corejs.javascript.Parser.addExpr(Parser.java:2170)
    at net.sourceforge.htmlunit.corejs.javascript.Parser.shiftExpr(Parser.java:2153)
    at net.sourceforge.htmlunit.corejs.javascript.Parser.relExpr(Parser.java:2130)
    at net.sourceforge.htmlunit.corejs.javascript.Parser.eqExpr(Parser.java:2104)
    at net.sourceforge.htmlunit.corejs.javascript.Parser.bitAndExpr(Parser.java:2095)
    at net.sourceforge.htmlunit.corejs.javascript.Parser.bitXorExpr(Parser.java:2086)
    at net.sourceforge.htmlunit.corejs.javascript.Parser.bitOrExpr(Parser.java:2077)
    at net.sourceforge.htmlunit.corejs.javascript.Parser.andExpr(Parser.java:2068)
    at net.sourceforge.htmlunit.corejs.javascript.Parser.orExpr(Parser.java:2059)
    at net.sourceforge.htmlunit.corejs.javascript.Parser.condExpr(Parser.java:2025)
    at net.sourceforge.htmlunit.corejs.javascript.Parser.assignExpr(Parser.java:1998)
    at net.sourceforge.htmlunit.corejs.javascript.Parser.expr(Parser.java:1979)
    at net.sourceforge.htmlunit.corejs.javascript.Parser.statementHelper(Parser.java:1025)
    at net.sourceforge.htmlunit.corejs.javascript.Parser.statement(Parser.java:891)
    at net.sourceforge.htmlunit.corejs.javascript.Parser.parse(Parser.java:535)
    at net.sourceforge.htmlunit.corejs.javascript.Parser.parse(Parser.java:456)
    at net.sourceforge.htmlunit.corejs.javascript.Context.compileImpl(Context.java:2496)
    at net.sourceforge.htmlunit.corejs.javascript.Context.compileString(Context.java:1456)
    at com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory$TimeoutContext.compileString(HtmlUnitContextFactory.java:201)
    at net.sourceforge.htmlunit.corejs.javascript.Context.compileString(Context.java:1448)
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$2.doRun(JavaScriptEngine.java:515)
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:669)
    ... 38 more
Enclosed exception: 
net.sourceforge.htmlunit.corejs.javascript.EvaluatorException: syntax error (http://localhost:8081/xyz/static/IKfETRJERwBRdVMGxGDGgTIvzB2B464w7472lQKpd3b.js#156)
    at com.gargoylesoftware.htmlunit.javascript.StrictErrorReporter.error(StrictErrorReporter.java:64)
    at net.sourceforge.htmlunit.corejs.javascript.Parser.addError(Parser.java:187)
    at net.sourceforge.htmlunit.corejs.javascript.Parser.addError(Parser.java:167)
    at net.sourceforge.htmlunit.corejs.javascript.Parser.reportError(Parser.java:219)
    at net.sourceforge.htmlunit.corejs.javascript.Parser.reportError(Parser.java:214)
    at net.sourceforge.htmlunit.corejs.javascript.Parser.mustMatchToken(Parser.java:366)
    at net.sourceforge.htmlunit.corejs.javascript.Parser.mustMatchToken(Parser.java:357)
    at net.sourceforge.htmlunit.corejs.javascript.Parser.xmlInitializer(Parser.java:2292)
    at net.sourceforge.htmlunit.corejs.javascript.Parser.unaryExpr(Parser.java:2252)
    at net.sourceforge.htmlunit.corejs.javascript.Parser.mulExpr(Parser.java:2184)
    at net.sourceforge.htmlunit.corejs.javascript.Parser.addExpr(Parser.java:2170)
    at net.sourceforge.htmlunit.corejs.javascript.Parser.shiftExpr(Parser.java:2153)
    at net.sourceforge.htmlunit.corejs.javascript.Parser.relExpr(Parser.java:2130)
    at net.sourceforge.htmlunit.corejs.javascript.Parser.eqExpr(Parser.java:2104)
    at net.sourceforge.htmlunit.corejs.javascript.Parser.bitAndExpr(Parser.java:2095)
    at net.sourceforge.htmlunit.corejs.javascript.Parser.bitXorExpr(Parser.java:2086)
    at net.sourceforge.htmlunit.corejs.javascript.Parser.bitOrExpr(Parser.java:2077)
    at net.sourceforge.htmlunit.corejs.javascript.Parser.andExpr(Parser.java:2068)
    at net.sourceforge.htmlunit.corejs.javascript.Parser.orExpr(Parser.java:2059)
    at net.sourceforge.htmlunit.corejs.javascript.Parser.condExpr(Parser.java:2025)
    at net.sourceforge.htmlunit.corejs.javascript.Parser.assignExpr(Parser.java:1998)
    at net.sourceforge.htmlunit.corejs.javascript.Parser.expr(Parser.java:1979)
    at net.sourceforge.htmlunit.corejs.javascript.Parser.statementHelper(Parser.java:1025)
    at net.sourceforge.htmlunit.corejs.javascript.Parser.statement(Parser.java:891)
    at net.sourceforge.htmlunit.corejs.javascript.Parser.parse(Parser.java:535)
    at net.sourceforge.htmlunit.corejs.javascript.Parser.parse(Parser.java:456)
    at net.sourceforge.htmlunit.corejs.javascript.Context.compileImpl(Context.java:2496)
    at net.sourceforge.htmlunit.corejs.javascript.Context.compileString(Context.java:1456)
    at com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory$TimeoutContext.compileString(HtmlUnitContextFactory.java:201)
    at net.sourceforge.htmlunit.corejs.javascript.Context.compileString(Context.java:1448)
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$2.doRun(JavaScriptEngine.java:515)
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:669)
    at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:602)
    at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:507)
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.compile(JavaScriptEngine.java:524)
    at com.gargoylesoftware.htmlunit.html.HtmlPage.loadJavaScriptFromUrl(HtmlPage.java:1144)
    at com.gargoylesoftware.htmlunit.html.HtmlPage.loadExternalJavaScriptFile(HtmlPage.java:1039)
    at com.gargoylesoftware.htmlunit.html.HtmlScript.executeScriptIfNeeded(HtmlScript.java:409)
    at com.gargoylesoftware.htmlunit.html.HtmlScript$3.execute(HtmlScript.java:266)
    at com.gargoylesoftware.htmlunit.html.HtmlScript.onAllChildrenAddedToPage(HtmlScript.java:286)
    at com.gargoylesoftware.htmlunit.html.HTMLParser$HtmlUnitDOMBuilder.endElement(HTMLParser.java:683)
    at com.gargoylesoftware.htmlunit.html.HTMLParser$HtmlUnitDOMBuilder.endElement(HTMLParser.java:642)
    at org.cyberneko.html.HTMLTagBalancer.callEndElement(HTMLTagBalancer.java:1170)
    at org.cyberneko.html.HTMLTagBalancer.endElement(HTMLTagBalancer.java:1072)
    at org.cyberneko.html.filters.DefaultFilter.endElement(DefaultFilter.java:206)
    at org.cyberneko.html.filters.NamespaceBinder.endElement(NamespaceBinder.java:330)
    at org.cyberneko.html.HTMLScanner$ContentScanner.scanEndElement(HTMLScanner.java:3116)
    at org.cyberneko.html.HTMLScanner$ContentScanner.scan(HTMLScanner.java:2083)
    at org.cyberneko.html.HTMLScanner.scanDocument(HTMLScanner.java:918)
    at org.cyberneko.html.HTMLConfiguration.parse(HTMLConfiguration.java:499)
    at org.cyberneko.html.HTMLConfiguration.parse(HTMLConfiguration.java:452)
    at com.gargoylesoftware.htmlunit.html.HTMLParser$HtmlUnitDOMBuilder.parse(HTMLParser.java:899)
    at com.gargoylesoftware.htmlunit.html.HTMLParser.parse(HTMLParser.java:242)
    at com.gargoylesoftware.htmlunit.html.HTMLParser.parseHtml(HTMLParser.java:188)
    at com.gargoylesoftware.htmlunit.DefaultPageCreator.createHtmlPage(DefaultPageCreator.java:268)
    at com.gargoylesoftware.htmlunit.DefaultPageCreator.createPage(DefaultPageCreator.java:156)
    at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.java:437)
    at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:311)
    at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:393)
    at com.gargoylesoftware.htmlunit.html.HtmlPage.refresh(HtmlPage.java:2234)
    at org.openqa.selenium.htmlunit.HtmlUnitDriver$HtmlUnitNavigation.refresh(HtmlUnitDriver.java:1282)
    at geb.Browser.go(Browser.groovy:395)
    at geb.Page.to(Page.groovy:184)
    at geb.Browser.via(Browser.groovy:475)
    at geb.Browser.to(Browser.groovy:434)
    at geb.Browser.to(Browser.groovy:412)
    at geb.junit4.GebTest.methodMissing(GebTest.groovy:52)
.....

When javascript is not enabled, the tests for pages without javascript pass but tests for pages with javascript get the following:

java.lang.UnsupportedOperationException: Javascript is not enabled for this HtmlUnitDriver instance
    at org.openqa.selenium.htmlunit.HtmlUnitDriver.getPageToInjectScriptInto(HtmlUnitDriver.java:639)
    at org.openqa.selenium.htmlunit.HtmlUnitDriver.executeScript(HtmlUnitDriver.java:590)
    at geb.js.JavascriptInterface._execjs(JavascriptInterface.groovy:41)
    at geb.js.JavascriptInterface.exec(JavascriptInterface.groovy:71)
    at geb.js.JQueryAdapter._callJQueryMethod(JQueryAdapter.groovy:33)
    at geb.js.JQueryAdapter.methodMissing(JQueryAdapter.groovy:60)
    at com.sra.ridge.geb.page.RidgePage.populateSecurityQuestions(RidgePage.groovy:95)
    at geb.Browser.methodMissing(Browser.groovy:194)

Any suggestions for how to handle these issues? These tests passed when using grails 2.2.3 and geb 0.9.0-RC-1

Upvotes: 0

Views: 762

Answers (1)

user3250428
user3250428

Reputation: 1

The syntax error was apparently due to the hashing of javascript files by the resource plugin and setting

grails.resources.mappers.hashandcache.excludes = ['*/'] 

in the test environment in Config.groovy fixed the issue of the exception.

Using geb 0.9.0-RC1 fixed the issue of the tests running twice. It is unfortunate that we can't upgrade to 0.9.2 of geb.

Upvotes: 0

Related Questions