Getting Started with WebDriverManager
Selenium WebDriver is a widely used framework for browser automation, but managing browser drivers manually can be time-consuming and error-prone across different browsers and environments. WebDriverManager simplifies this process by automatically downloading, configuring, and maintaining the correct driver versions, making Selenium test setup faster and easier. Let us delve into understanding Selenium WebDriverManager and how it simplifies browser driver setup in automation testing.
1. Introduction to WebDriverManager
When Selenium WebDriver starts a browser session, it requires a browser-specific driver that acts as a bridge between the test code and the browser, such as ChromeDriver for Google Chrome, GeckoDriver for Mozilla Firefox, EdgeDriver for Microsoft Edge, and SafariDriver for Safari (Safari WebDriver documentation). Before WebDriverManager, testers had to manually download the appropriate driver, place it in a known location, configure system properties in their code, and update the driver whenever browser versions changed. This process increased maintenance effort and frequently caused test failures due to driver-browser version mismatches. WebDriverManager automates these tasks by automatically downloading, configuring, and managing the correct driver versions.
2. Understanding WebDriverManager
WebDriverManager is an open-source Java library developed by Boni García that automates the management of browser drivers required by Selenium WebDriver. Its key features include automatic driver download, browser-driver version matching, cross-platform support, elimination of manual driver configuration, and support for major browsers such as Chrome, Firefox, Edge, and Opera. By integrating seamlessly with Selenium WebDriver, WebDriverManager reduces maintenance effort, improves test reliability, removes the dependency on locally managed drivers, and simplifies CI/CD pipeline setup.
3. Getting Started with WebDriverManager
3.1 Adding WebDriverManager Dependencies
To set up Selenium automation with WebDriverManager, you need to include the required dependencies in your Maven project. These dependencies enable browser automation, driver management, and support for different testing frameworks.
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>stable__jar__version</version>
</dependency>
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>stable__jar__version</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>stable__jar__version</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>stable__jar__version</version>
<scope>test</scope>
</dependency>
The above Maven configuration defines the core libraries required for building a Selenium automation framework with WebDriverManager.
- The first dependency (
selenium-java) provides the Selenium WebDriver APIs, which are used to interact with web browsers and perform automation actions such as opening URLs, clicking elements, and validating page content. - The second dependency (
webdrivermanager) is responsible for automatically downloading, setting up, and managing the correct browser driver binaries (such as ChromeDriver, GeckoDriver, or EdgeDriver). This removes the need for manual driver configuration. - The third dependency (
junit-jupiter) adds support for JUnit 5, a widely used testing framework that provides annotations, assertions, and lifecycle management for writing structured test cases. - The fourth dependency (
testng) adds TestNG support, another powerful testing framework that enables advanced test execution features such as grouping, parallel execution, and flexible test configuration.
Together, these dependencies form a complete test automation setup that supports Selenium WebDriver execution, automated driver management, and multiple testing frameworks for scalable test design.
3.2 Running Selenium Tests Across Multiple Browsers
The following example demonstrates how WebDriverManager can be used to execute Selenium tests across multiple browsers without manually managing browser driver executables. It shows a consistent approach for launching Chrome, Firefox, and Edge while automatically handling driver setup for each browser.
// MultiBrowserTest.java
import io.github.bonigarcia.wdm.WebDriverManager;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.edge.EdgeDriver;
public class MultiBrowserTest {
public static void main(String[] args) {
// Execute Chrome Test
runChromeTest();
// Execute Firefox Test
runFirefoxTest();
// Execute Edge Test
runEdgeTest();
}
private static void runChromeTest() {
System.out.println("===== Chrome Test =====");
WebDriverManager.chromedriver().setup();
WebDriver driver = new ChromeDriver();
driver.get("https://www.google.com");
System.out.println("Page Title: " + driver.getTitle());
driver.quit();
}
private static void runFirefoxTest() {
System.out.println("\n===== Firefox Test =====");
WebDriverManager.firefoxdriver().setup();
WebDriver driver = new FirefoxDriver();
driver.get("https://www.wikipedia.org");
System.out.println("Page Title: " + driver.getTitle());
driver.quit();
}
private static void runEdgeTest() {
System.out.println("\n===== Edge Test =====");
WebDriverManager.edgedriver().setup();
WebDriver driver = new EdgeDriver();
driver.get("https://www.microsoft.com");
System.out.println("Page Title: " + driver.getTitle());
driver.quit();
}
}
3.2.1 Code Explanation
The MultiBrowserTest class demonstrates how to use WebDriverManager with multiple browsers in a single Selenium application. The program begins by importing the required Selenium WebDriver classes along with WebDriverManager. Inside the main() method, three separate methods—runChromeTest(), runFirefoxTest(), and runEdgeTest()—are invoked sequentially to execute browser-specific tests. In the Chrome test, WebDriverManager.chromedriver().setup() automatically downloads and configures the appropriate ChromeDriver, after which a new ChromeDriver instance is created. The browser navigates to Google using driver.get(“https://www.google.com”), retrieves the page title using driver.getTitle(), prints it to the console, and then closes the browser using driver.quit(). The Firefox test follows the same workflow, using WebDriverManager.firefoxdriver().setup() and FirefoxDriver to open Wikipedia and display its page title. Similarly, the Edge test uses WebDriverManager.edgedriver().setup() and EdgeDriver to launch Microsoft Edge, navigate to Microsoft’s website, print the page title, and close the browser. This example highlights one of the key benefits of WebDriverManager: it eliminates the need to manually download, configure, and maintain browser driver executables while providing a consistent approach for running Selenium tests across multiple browsers.
3.2.2 Code Output
When the program is executed, it runs the Selenium tests sequentially in Chrome, Firefox, and Microsoft Edge. For each browser, the application opens the specified website, retrieves the page title, displays it in the console, and then closes the browser before proceeding to the next test.
===== Chrome Test ===== Page Title: Google ===== Firefox Test ===== Page Title: Wikipedia ===== Edge Test ===== Page Title: Microsoft – Official Home Page
During execution, the program launches Chrome, Firefox, and Microsoft Edge sequentially. Each browser navigates to its respective website, retrieves the page title using driver.getTitle(), prints the title to the console, and then closes the browser before the next test begins.
3.3 Integrating WebDriverManager with JUnit 5
This example demonstrates how WebDriverManager can be integrated with JUnit 5 to automate browser-based testing. By combining Selenium WebDriver, WebDriverManager, and JUnit 5 lifecycle annotations, the test setup, execution, and cleanup process becomes structured, maintainable, and easy to manage.
// GoogleTitleTest.java
import io.github.bonigarcia.wdm.WebDriverManager;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class GoogleTitleTest {
private WebDriver driver;
@BeforeEach
void setup() {
// Download and configure ChromeDriver
WebDriverManager.chromedriver().setup();
// Launch Chrome browser
driver = new ChromeDriver();
}
@Test
void verifyGoogleTitle() {
// Open Google
driver.get("https://www.google.com");
// Verify page title
Assertions.assertEquals("Google", driver.getTitle());
System.out.println("Page Title: " + driver.getTitle());
}
@AfterEach
void tearDown() {
// Close browser
driver.quit();
}
}
3.3.1 Code Explanation
The GoogleTitleTest class demonstrates the integration of WebDriverManager with JUnit 5 and Selenium WebDriver. A private WebDriver instance is declared at the class level so it can be shared across test methods. The @BeforeEach annotation marks the setup() method, which executes before every test case. Inside this method, WebDriverManager.chromedriver().setup() automatically downloads and configures the appropriate ChromeDriver version, eliminating the need for manual driver management. A new ChromeDriver instance is then created to launch the Chrome browser. The @Test annotation identifies the verifyGoogleTitle() method as a test case. This method navigates to Google using driver.get(“https://www.google.com”) and validates the page title using JUnit’s Assertions.assertEquals() method. If the actual title matches the expected value of “Google”, the test passes; otherwise, it fails. The page title is also printed to the console for verification. Finally, the @AfterEach annotation marks the tearDown() method, which executes after every test and closes the browser using driver.quit(), ensuring proper cleanup of resources. This structure follows JUnit 5 testing best practices by separating setup, test execution, and cleanup logic into dedicated lifecycle methods.
3.3.2 Code Output
When the test is executed, Chrome launches automatically, navigates to Google, validates the page title, and reports the test result through the JUnit framework. The following output illustrates a successful test execution.
Page Title: Google BUILD SUCCESSFUL Tests run: 1 Passed: 1 Failed: 0 Skipped: 0
The browser launches automatically, navigates to Google, verifies that the page title is “Google”, prints the title in the console, marks the test as passed, and then closes the browser. This example showcases how WebDriverManager simplifies browser driver management while JUnit 5 provides a structured framework for automated test execution.
3.4 Integrating WebDriverManager with TestNG
This example demonstrates how WebDriverManager can be integrated with TestNG to automate browser-based testing. WebDriverManager handles browser driver setup automatically, while TestNG provides annotations for managing test initialization, execution, validation, and cleanup.
// TestNGExample.java
import io.github.bonigarcia.wdm.WebDriverManager;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.Assert;
import org.testng.annotations.*;
public class TestNGExample {
private WebDriver driver;
@BeforeMethod
public void setup() {
WebDriverManager.chromedriver().setup();
driver = new ChromeDriver();
}
@Test
public void verifyGoogleTitle() {
driver.get("https://www.google.com");
Assert.assertEquals(driver.getTitle(), "Google");
System.out.println("Page Title: " + driver.getTitle());
}
@AfterMethod
public void tearDown() {
driver.quit();
}
}
3.4.1 Code Explanation
The TestNGExample class demonstrates the use of WebDriverManager with the TestNG testing framework. A private WebDriver instance is declared at the class level and initialized in the @BeforeMethod annotated setup() method. Inside this method, WebDriverManager.chromedriver().setup() automatically downloads and configures the appropriate ChromeDriver version, after which a new ChromeDriver instance is created. The @Test annotated verifyGoogleTitle() method opens Google’s homepage, retrieves the page title, and validates it using TestNG’s Assert.assertEquals() method. If the actual title matches the expected value of “Google”, the test passes successfully. The page title is also printed to the console for verification. Finally, the @AfterMethod annotated tearDown() method executes after the test completes and closes the browser using driver.quit(). This approach ensures proper resource cleanup while maintaining a clear separation between setup, test execution, and teardown activities.
3.4.2 Code Output
When the TestNG test is executed, Chrome launches automatically, navigates to Google, validates the page title, and reports the test result through the TestNG framework. The following output illustrates a successful test execution.
Page Title: Google =============================================== Default Suite Total tests run: 1 Passes: 1 Failures: 0 Skips: 0 ===============================================
The output confirms that WebDriverManager successfully configured the required ChromeDriver, the browser was launched correctly, and the page title matched the expected value. After the test execution completes, the browser session is closed automatically by the tearDown() method, demonstrating how WebDriverManager and TestNG work together to simplify automated test execution and resource management.
3.5 Executing Remote Tests with Selenium Grid
This example demonstrates how WebDriverManager can be used alongside Selenium Grid to execute browser automation tests on remote machines. Selenium Grid enables distributed test execution across different browsers, operating systems, and environments, while WebDriverManager simplifies local driver management and browser configuration.
// SeleniumGridExample.java
import io.github.bonigarcia.wdm.WebDriverManager;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.RemoteWebDriver;
import java.net.URL;
public class SeleniumGridExample {
public static void main(String[] args) throws Exception {
WebDriverManager.chromedriver().setup();
ChromeOptions options = new ChromeOptions();
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444"), options);
driver.get("https://www.selenium.dev");
System.out.println("Page Title: " + driver.getTitle());
driver.quit();
}
}
3.5.1 Code Explanation
The SeleniumGridExample class demonstrates how to execute Selenium tests on a Selenium Grid using a remote browser session. The program begins by importing the required Selenium and WebDriverManager classes. Inside the main() method, WebDriverManager.chromedriver().setup() ensures that the appropriate ChromeDriver version is available and configured. A ChromeOptions object is then created to define the browser capabilities that will be used for the remote session. The RemoteWebDriver is initialized by connecting to the Selenium Grid Hub running at http://localhost:4444. Once the connection is established, Selenium requests a Chrome browser session from one of the available Grid nodes. The browser navigates to the Selenium website using driver.get(), retrieves the page title through driver.getTitle(), and prints it to the console. Finally, driver.quit() closes the remote browser session and releases the allocated Grid resources. This example illustrates how Selenium Grid enables remote and distributed test execution while maintaining the same WebDriver programming model used for local browser automation.
3.5.2 Code Output
When the program is executed, Selenium connects to the Selenium Grid Hub, requests a Chrome browser session from an available node, navigates to the Selenium website, retrieves the page title, and prints it to the console. The following output illustrates a successful remote test execution.
Page Title: Selenium
The output confirms that the remote browser session was created successfully through Selenium Grid and that the test executed on a Grid node rather than the local machine. After retrieving and displaying the page title, the browser session is terminated using driver.quit(), releasing the resources allocated by Selenium Grid. This demonstrates how Selenium Grid enables scalable and distributed test execution while maintaining the familiar Selenium WebDriver programming model.
4. Conclusion
WebDriverManager has become an essential utility for Selenium automation engineers. It eliminates the burden of manually managing browser drivers, automatically downloads the correct driver versions, and simplifies Selenium test setup across local and CI/CD environments. Whether you are using plain Selenium WebDriver, JUnit, TestNG, Selenium Grid, or Spring Boot, WebDriverManager significantly improves productivity and reduces maintenance overhead. By adopting WebDriverManager, teams can focus more on writing reliable test automation and less on infrastructure-related issues.




