Sebastian Flückiger Sebastian Flückiger - 4 months ago 18
Groovy Question

Functional Tests with Grails, Geb & PhantomJS not working

I am running Spock tests with Gebish & HtmlUnitDriver. So far so good.

For reasons of speed I am changing the driver to PhantomJS: http://phantomjs.org/

my

GebConfigs.groovy
looks like this:

import org.openqa.selenium.phantomjs.PhantomJSDriver
import org.openqa.selenium.remote.DesiredCapabilities
import org.openqa.selenium.WebDriver
import org.openqa.selenium.Dimension

driver {
ArrayList cliArgsCap = new ArrayList();
cliArgsCap.add("--web-security=false");
cliArgsCap.add("--ssl-protocol=any");
cliArgsCap.add("--ignore-ssl-errors=true");

DesiredCapabilities desiredCapabilities = new DesiredCapabilities()
desiredCapabilities.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, cliArgsCap);

PhantomJSDriver d = new PhantomJSDriver(desiredCapabilities)
d
}


as you see, no matter what a PhantomJSDriver should be used for tests.

my
BuildConfig.groovy


test "org.gebish:geb-spock:$gebVersion"
test "org.seleniumhq.selenium:selenium-chrome-driver:$seleniumVersion"
test "org.seleniumhq.selenium:selenium-remote-driver:$seleniumVersion"
test "org.seleniumhq.selenium:selenium-htmlunit-driver:$seleniumVersion"
test "org.seleniumhq.selenium:selenium-support:$seleniumVersion"
test "org.spockframework:spock-grails-support:0.7-groovy-2.0"


test "org.grails:grails-datastore-test-support:1.0-grails-2.4"

test( "com.github.detro.ghostdriver:phantomjsdriver:1.1.0" ) {
transitive = false
}


the phantomjs.exe is located in:

C:\Apps\selenium\phantomjs\phantomjs.exe


and
C:\Apps\selenium\phantomjs
is in my
PATH
. i can run it through
cmd: phantomjs
in interactive mode.

problem

for some unclear reason geb is still using a HtmlUnitDriver. see log:

Error |
2014-08-15 14:01:26,630 [JS executor for com.gargoylesoftware.htmlunit.WebClient@527a4013] ERROR
javascript.StrictErrorReporter - runtimeError: message=[The data necessary to complete this
operation is not yet available.] sourceName=[http://localhost:8080/myapp/aui/js/aui-all.js] line=
[1] lineSource=[null] lineOffset=[0]


any ideas why phantomjsdriver is not used in this case?

Answer

I have phantomjs up and running with a Grails 2.0.4 app. My buildConfig.groovy looks like this:

def gebVersion = "0.9.2"
def seleniumVersion = "2.35.0"

...

    test "org.gebish:geb-spock:$gebVersion"
    test "org.gebish:geb-junit4:$gebVersion"        
    test( "com.github.detro.ghostdriver:phantomjsdriver:1.0.1" ) {
        transitive = false
        exclude "xml-apis"
        exclude "xercesImpl"
    }
    test ("org.seleniumhq.selenium:selenium-remote-driver:$seleniumVersion") { // Needed by phantomjsdriver
        exclude "xerces"
        exclude "xercesImpl"
    }

hope that helps

Update: had to work a little bit on my own example, but the result is a working Grails 2.4.2 app with phantomjs: https://github.com/rdmueller/SO25324259 (sorry for the horrible formatting - only saw it after my checkin).

btw: I didn't get your DesiredCapabilities to work :-(

PS: did you know the report feature? https://github.com/rdmueller/SO25324259/blob/master/test/functional/DemoSpec.groovy#L14

It takes a screenshot with your headless phantomjs browser - really cool feature!