Groovy with Geb using Phantomjs and ssl certs

Here is my setup for using self signed certs and allowing the PhantomJsDriver to use Phantomjs and hit https pages while using self signed certificates.

Read Tomás Lin’s excellent post on setting up Geb with Phantomjs.

The phantomjsdriver will producde a log file phantomjsdriver.log when creating the instance of phantomjs.

Negotiated Capabilities: {“browserName”:”phantomjs”,”version”:”1.9.1″,”driverName”:”ghostdriver”,”driverVersion”:”1.0.3″,”platform”:”mac-10.8 (Mountain Lion)-32bit”,”javascriptEnabled”:true,”takesScreenshot”:true,”handlesAlerts”:false,”databaseEnabled”:false,”locationContextEnabled”:false,”applicationCacheEnabled”:false,”browserConnectionEnabled”:false,”cssSelectorsEnabled”:true,”webStorageEnabled”:false,”rotatable”:false,“acceptSslCerts”:false,”nativeEvents”:true,”proxy”:{“proxyType”:”direct”}}

AcceptSslCerts is shown as false in the log, but the below code will use command line arguments to force phantomjs to accept any certificate.  The value we are most interested in is –ignore-ssl-errors=true

Tested Configuration:
phantomjs = 1.9.1
webdriver = 2.33
geb = 0.6.3
grails = 1.3.9
phantomjsdriver = 1.0.4
mac os x 10.8.4

If updating your webdriver to version 2.33 you will have to also include the selenium-remote-driver to get it to work else the test will fail not being able to find the RemoteWebDriver class.

Here is my grails dependencies {

def gebVersion = "0.6.3"
def webdriverVersion = '2.33.0'

dependencies {
		test "org.codehaus.geb:geb-spock:$gebVersion"
		test "org.spockframework:spock-grails-support:0.6-groovy-1.7"
		test "org.seleniumhq.selenium:selenium-remote-driver:$webdriverVersion"
		test "org.seleniumhq.selenium:selenium-support:$webdriverVersion"
		test( "com.github.detro.ghostdriver:phantomjsdriver:1.0.4" ) {
			transitive = false
plugins {
		test ":spock:0.5-groovy-1.7"
		test ":geb:$gebVersion"

Setting up the driver in Groovy to allow self signed certs.  Put this in your GebConfig.groovy

driver = {
    ArrayList cliArgsCap = new ArrayList();

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

    PhantomJSDriver d = new PhantomJSDriver(desiredCapabilities)


One thought on “Groovy with Geb using Phantomjs and ssl certs

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s