Automatically download OS-specific WebDriver executable

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
environments {
    chrome {
        // Download and configure ChromeDriver using
        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:

Happy testing!

One thought on “Automatically download OS-specific WebDriver executable

  1. Javed says:

    great soloution. thanks Man.

Leave a Reply

Your email address will not be published. Required fields are marked *