Geb Quickie: Automatically download drivers for Chrome and Internet Explorer

A common error encountered by Geb beginners using Webdriver with Chrome or Internet Explorer is that they forget to download and properly configure chromedriver / iedriver.

In this post, I will show you how to set up your project so that it ensures that your driver file is available for your tests. ( Credit Marcin Erdmann for initial implementation ).

We start with the GebConfig provided in the grails-geb-example project. So the environment for chrome looks like this:

environments {

    // run as “grails -Dgeb.env=chrome test-app”
    // See:
    chrome {
        driver = { new ChromeDriver() }


We’re going to modify the chrome section so that it sets up the latest chromedriver for mac. To do so, we must download the latest chromedriver if it does not exists.

For this project, I’m going to put the latest chromedriver in /test/drivers/chrome/chromedriver, and am going to skip the download if the file already exists.

On the Mac, I also need to change my permissions so that chromedriver can execute.

I will use the ant builder available to groovy in my helper method, but you can use whatever you want. AntBuilder just makes it slightly easier to work with downloading and unzipping files.

The method looks like this:

private void downloadDriver(File file, String path) {
    if (!file.exists()) {
        def ant = new AntBuilder()
        ant.get(src: path, dest: '')
        ant.unzip(src: '', dest: file.parent)
        ant.delete(file: '')
        ant.chmod(file: file, perm: '700')

I will add this just above the environment block.

I now just need to call this downloadDriver method and set the environment variable:

environments {

    // run as “grails -Dgeb.env=chrome test-app”
    // See:
    chrome {
        def chromeDriver = new File('test/drivers/chrome/chromedriver')
        downloadDriver(chromeDriver, "")
        System.setProperty('', chromeDriver.absolutePath)
        driver = { new ChromeDriver() }


Notice that I pass in a mac specific chromedriver. But you can change _mac_ to _win_, _linux32_ or _linux64_. There are convenience methods provided by Apache Commons SystemUtils that come bundled with grails you can use to make this code more system specific.

I also set a system property for the chrome driver after it has been downloaded. (line 8).

Now, when I run the tests, it will automatically download chromedriver into the test/drivers directory if it doesn’t exist.

For your reference, a final GebConfig can be found here. The linked project also updates the example to grails 2.2.0.

Similarly, for internet explorer, you would need to use an IE driver, and the download link would look something like this:

def ieDriver = new File( 'test/drivers/ie/IEDriverServer.exe' )
downloadDriver( ieDriver, '' )
System.setProperty('', ieDriver.absolutePath)

Note the system property is and the file path is different.

One last thing, you would want to exclude the test/drivers directory recursively from your source control system.

Happy testing.


8 thoughts on “Geb Quickie: Automatically download drivers for Chrome and Internet Explorer

  1. Pingback: Geb Quickie: Automatically download drivers for Chrome and Internet Explorer | Nevada Java User Group

  2. anotherjay

    Thanks for this post. I got caught up on one thing which I think is just a typo:

    def chromeDriver = new File(‘test/drivers/chrome/chromedriver’)

    I had to change this to:

    def chromeDriver = new File(‘test/drivers/chrome/chromedriver.exe’)

    otherwise the “” system property gets set to “test\drivers\chrome\chromedriver” instead of “test\drivers\chrome\chromedriver.exe” and you get the following exception:

    Caused by: java.lang.IllegalStateException: The driver executable does not exist: path\to\project\test\drivers\chrome\chromedriver

    Just thought I’d leave that feedback in case someone else tries to use this example and runs into the same issue.

    Thanks again!

  3. Alex White

    Would you guys expect this code to work here in 2016? I can’t seem to get the code to run that loads the driver and sets the system property. Running the tests all fail: java.lang.IllegalStateException: The path to the driver executable must be set by the system property;

  4. Pingback: An Army of Solipsists » Blog Archive » This Week in Grails (2013-01)

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