Automatically download OS-specific WebDriver executable

Automatically download and setup OS-specific Webdriver executables..

Object Partners

When using the Selenium browser functional testing library, testing with some browsers requires using an operating system-specific executable in addition to the driver .jar file. For example, when running Selenium tests with Chrome you need to have the ChromeDriver executable for the operating system you are using. Internet Explorer also requires a similar executable to run tests with it.

Having to manually download and manage these drivers for each operating systems you run tests on is a pain. Each developer on your team has their own laptop, potentially running different operating systems. Plus your continuous integration environment may be on a different OS.

In the past I used some custom download code in each project I worked on to detect the OS and download the driver. But carrying that download code from project to project is also inconvenient. I’d planned for years to write a small library to do the same thing, but thankfully someone else recently did it already!

The WebDriverManager project by Boni Garcia automatically handles downloading and configuring the drivers for your operating system. And it’s very easy to use.

First, add the dependency in your project’s build file. In this example I’m using Gradle as my build system, so I add this to build.gradle:

dependencies {
    // For downloading browser-specific drivers that browsers like Chrome and IE require
    testCompile("io.github.bonigarcia:webdrivermanager:1.4.1") {
        exclude group: 'org.seleniumhq.selenium'
    }
}

Next, add code to download and configure the driver before the tests run. In this example I’m using Geb to write my tests, so in my GebConfig.groovy I add:

import io.github.bonigarcia.wdm.ChromeDriverManager
import org.openqa.selenium.chrome.ChromeDriver  

environments {
    chrome {
        // Download and configure ChromeDriver using https://github.com/bonigarcia/webdrivermanager
        ChromeDriverManager.getInstance().setup()  

        driver = { new ChromeDriver() }
    }
}

Now when I run my Geb tests in the ‘chrome’ environment, WebDriverManager will automatically download the ChromeDriver executable for my OS and set up the required system property to use it. It’s that easy!

For a full working example of using WebDriverManager with Geb, check out this example project on Github: https://github.com/craigatk/grails3-geb-example

Happy testing!

Share this Post

Related Blog Posts

Unknown

Setting Up the Raspberry Pi 3 for Home Assistant

April 12th, 2016

A guide to set up a Raspberry Pi 3 with Home Assistant

Igor Shults
Unknown

Using OAuth 2.0 With Google APIs

January 21st, 2016

Google has been updating their APIs to require OAuth 2.0. One of our clients makes considerable use of the Google Webmaster Tools APIs instrumented for 14,629 individual websites (and growing). I recently had the opportunity to help this client…

Object Partners
Unknown

Celebrating our 20th year in business!

January 6th, 2016

At the end of January, Object Partners will have officially been in business for 20 years. While that sounds like a very long time, it’s gone by quickly for some of us old timers. When we started OPI, we wanted it to be the kind of place where…

Chris Spurgat

About the author