How to Automate Browser Driver Management with WebDriverManager in Java

By

How to Automate Browser Driver Management with WebDriverManager in Java

Automating web interactions in Java with Selenium is straightforward—until you face the browser driver mismatch problem. Every browser version requires a specific driver binary, and a small update can break your tests. Manually downloading, storing, and updating drivers is tedious and error-prone, especially in team or CI/CD environments. WebDriverManager is a Java library that solves this by automatically resolving, downloading, and configuring the correct driver for your installed browser—no manual System.setProperty calls needed. This guide walks you through setting up and using WebDriverManager step by step.

How to Automate Browser Driver Management with WebDriverManager in Java
Source: www.baeldung.com

What You Need

Step-by-Step Guide

Step 1: Understand the Problem WebDriverManager Solves

Before coding, recognize why manual driver management fails. With traditional Selenium, you have to:

WebDriverManager eliminates this friction. It detects the installed browser version, finds the compatible driver, downloads it to a cache, and sets all required system properties automatically.

Step 2: Add WebDriverManager as a Dependency

WebDriverManager is available on Maven Central. Add it to your project’s build file.

For Maven (pom.xml):

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

For Gradle (build.gradle):

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

Many projects also use Selenium; ensure you have the selenium-java dependency as well.

Step 3: Configure WebDriverManager in Your Code

After adding the dependency, replace the manual System.setProperty call with a one-liner. For Chrome:

import io.github.bonigarcia.wdm.WebDriverManager;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class WebDriverManagerDemo {
    public static void main(String[] args) {
        WebDriverManager.chromedriver().setup();
        WebDriver driver = new ChromeDriver();
        driver.get("https://example.com");
        // your test code here
        driver.quit();
    }
}

The setup() method checks your Chrome version, downloads the matching ChromeDriver binary (if not already cached), and sets webdriver.chrome.driver automatically.

Step 4: Use WebDriverManager with Different Browsers

WebDriverManager supports all major browsers. Replace chromedriver() with the appropriate method:

For headless testing, you can still use the same setup; just configure browser options as usual.

Step 5: Integrate with Testing Frameworks (JUnit/TestNG)

In a typical test automation project, you’ll use WebDriverManager inside a @BeforeAll or @BeforeEach method. Example with JUnit 5:

How to Automate Browser Driver Management with WebDriverManager in Java
Source: www.baeldung.com
import static io.github.bonigarcia.wdm.WebDriverManager.*;

public class LoginTest {
    WebDriver driver;

    @BeforeEach
    void setUp() {
        chromedriver().setup();
        driver = new ChromeDriver();
    }

    @Test
    void testLogin() {
        driver.get("https://my-app.com/login");
        // assertions
    }

    @AfterEach
    void tearDown() {
        driver.quit();
    }
}

WebDriverManager also integrates seamlessly with Selenium Grid and Docker. Use WebDriverManager.chromedriver().driverInDocker() to run tests in containers.

Step 6: Take Advantage of Advanced Features

Beyond basic setup, WebDriverManager offers powerful capabilities:

These features make WebDriverManager suitable for both local development and CI/CD pipelines where environment consistency is critical.

Tips and Best Practices

By adopting WebDriverManager, you eliminate a whole category of test flakiness caused by driver mismatches. Your setup becomes portable, maintainable, and ready for modern CI/CD workflows.

Tags:

Related Articles

Recommended

Discover More

May 2026's Must-Read Sci-Fi & Fantasy: A Curated GuideMastering Distributed Caching in .NET with Postgres on Azure: A Q&A GuideFrom Coding Novice to AI Agent Builder: A Beginner's Step-by-Step Guide to Creating a Leaderboard-Cracking AIYour Guide to Microsoft's New AI, Data, and Development Certificates on CourseraFedora Linux 44: What's New and How to Upgrade