End-to-end Testing
6 min read

What is Selenium WebDriverManager?

Manage the download, upgrade, and maintenance of WebDriver versions in your own testing infrastructure via the open-source WebDriverManager library.

Joel Adewole
Published August 3, 2022

Selenium is one of the most well-known technologies in the software testing space. With built-in support for all major browsers, Selenium is a powerful tool for building automated tests that can be run in a variety of environments.

In order for Selenium to communicate with a browser, the browser needs to implement something called a WebDriver. This is the interface that defines how Selenium can execute various operations within the browser, like clicks and text entries. Each major browser has its own WebDriver implementation that is updated with every major browser release. The communication protocol between the Selenium runtime and the browser’s WebDriver is known as the WebDriver API. The WebDriver API is the only standards-based communication protocol across browsers and is defined in a W3C Spec that is written and updated by representatives from browser vendors, tool vendors, and the open-source community.

This article will discuss WebDriverManager, compare it to another related tool called Selenium Grid, and provide information on how you can use WebDriverManager in your own projects.

Overview

WebDriverManager is an open-source Java library developed by Boni Garcia to enable developers to manage the WebDriver versions within their own testing infrastructure. Instead of having a manual process for downloading, upgrading, and maintaining WebDriver versions, WebDriverManager provides an abstraction that handles these tasks.

WebDriverManager currently supports Chrome, Firefox, Internet Explorer, Opera, Microsoft Edge, and Safari.

Features of Selenium WebDriverManager

The major features provided by WebDriverManager are:

Differences between WebDriverManager and Selenium Grid

WebDriverManager and Selenium Grid could easily be confused as they both integrate with Selenium and work with WebDrivers. While Selenium Grid enables remote WebDriver script execution on virtual or physical machines by transferring commands from clients to the browser instances, WebDriverManagers assist in automating the installation, configuration, and execution of WebDrivers in test environments.

WebDriverManager

WebDriverManager performs the following tasks to successfully perform a driver management process:

  1. Download: WebDrivers are binary files specific to certain browsers, so it is essential to determine the type and version of the browser. It is also important to know the operating system of the test environment before downloading the WebDriver. In this situation, WebDriverManager can assist in downloading the appropriate WebDriver.

  2. Setup: After downloading the appropriate WebDriver to our test environment, setting up could be time-consuming. Traditionally, we manually specify the path of the WebDriver using the ‘System.setProperty’ method, like this:

    System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver");
    

    After downloading the WebDriver, this procedure is managed automatically by WebDriverManager.

  3. Maintenance: Lastly, as time passes, when browser providers update their products, the installed WebDrivers in the test environment might become incompatible with the updated browser versions. When necessary, WebDriverManager upgrades the WebDriver to manage the changes.

Selenium Grid

On the other hand, Selenium Grid addresses a subset of issues concerning distributions and delegations but does not manage the infrastructure for driver management.

The tasks carried out by Selenium Grid include:

Selenium Grid and WebDriverManager are mostly complementary technologies that can work great together, with WebDriverManager handling the maintenance of WebDriver versions, and Selenium Grid providing utilities for running cross-browser tests at scale.

Configuration

To begin using WebDriverManager, Selenium WebDriver must be installed first in your test environment (machine).

WebDriverManager can be declared in the ‘pom.xml’ file as follows using Maven’s test scope:

<dependency>
    <groupId>io.github.bonigarcia</groupId>
    <artifactId>webdrivermanager</artifactId>
    <version>5.2.1</version>
    <scope>test</scope>
</dependency>

In Gradle, WebDriverManager can be declared as follows:

dependencies {
  testImplementation("io.github.bonigarcia:webdrivermanager:5.2.1")
}

Advanced options

The Java API of the WebDriverManager includes configuration. To call desired options, each browser manager utilizes a different function of this API.

WebDriverManager can offer driver binaries for various browsers by calling the “setup()” method on each browser driver manager. The following are some examples for these managers:

WebDriverManager.chromedriver().setup(); // For chrome browser

WebDriverManager.firefoxdriver().setup(); // For Firefox browser

WebDriverManager.edgedriver().setup(); // For Microsoft Edge browser

WebDriverManager.operadriver().setup(); // For Opera browser

WebDriverManager.iedriver().setup(); // For Internet Explorer browser

WebDriverManager.chromiumdriver().setup();  // For Chromium browser

In the example above, we do not specify which driver version should be loaded, and instead rely on WebDriverManager to resolve the appropriate WebDriver version using their resolution algorithm.

We can instead include the version number ourselves. The ‘driverVersion()’ method allows us to specify the exact WebDriver version to use:

WebDriverManager.chromedriver().driverVersion("81.0.4044.138").setup();

The browserVersion method can be used to specify which version of the underlying browser (not WebDriver) should be used. This is useful when you have multiple versions of the same browser installed (such as Chrome and Chrome Canary) and don’t want to rely on the resolution algorithm to choose the proper version.

WebDriverManager.firefoxdriver().browserVersion("75").setup();

Try Reflect: A modern cross-browser testing platform

Reflect is a no-code testing platform that lets you build and run tests across all popular browsers. Instead of building and maintaining your own infrastructure, using a cloud platform like Reflect allows you to get the benefits of automated cross-browser testing without the headache of maintaining an entire testing grid yourself.

Try it for free.

Get started with Reflect today

Create your first test in 2 minutes, no installation or setup required. Accelerate your testing efforts with fast and maintainable test suites without writing a line of code.

Copyright © 2022 Reflect Software Inc. All Rights Reserved.