Sebastian Flückiger Sebastian Flückiger - 1 year ago 155
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:


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();

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

PhantomJSDriver d = new PhantomJSDriver(desiredCapabilities)

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


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:


is in my
. i can run it through
cmd: phantomjs
in interactive mode.


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 Source

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: (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?

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download