eBook – Guide Spring Cloud – NPI EA (cat=Spring Cloud)
announcement - icon

Let's get started with a Microservice Architecture with Spring Cloud:

>> Join Pro and download the eBook

eBook – Mockito – NPI EA (tag = Mockito)
announcement - icon

Mocking is an essential part of unit testing, and the Mockito library makes it easy to write clean and intuitive unit tests for your Java code.

Get started with mocking and improve your application tests using our Mockito guide:

Download the eBook

eBook – Java Concurrency – NPI EA (cat=Java Concurrency)
announcement - icon

Handling concurrency in an application can be a tricky process with many potential pitfalls. A solid grasp of the fundamentals will go a long way to help minimize these issues.

Get started with understanding multi-threaded applications with our Java Concurrency guide:

>> Download the eBook

eBook – Reactive – NPI EA (cat=Reactive)
announcement - icon

Spring 5 added support for reactive programming with the Spring WebFlux module, which has been improved upon ever since. Get started with the Reactor project basics and reactive programming in Spring Boot:

>> Join Pro and download the eBook

eBook – Java Streams – NPI EA (cat=Java Streams)
announcement - icon

Since its introduction in Java 8, the Stream API has become a staple of Java development. The basic operations like iterating, filtering, mapping sequences of elements are deceptively simple to use.

But these can also be overused and fall into some common pitfalls.

To get a better understanding on how Streams work and how to combine them with other language features, check out our guide to Java Streams:

>> Join Pro and download the eBook

eBook – Jackson – NPI EA (cat=Jackson)
announcement - icon

Do JSON right with Jackson

Download the E-book

eBook – HTTP Client – NPI EA (cat=Http Client-Side)
announcement - icon

Get the most out of the Apache HTTP Client

Download the E-book

eBook – Maven – NPI EA (cat = Maven)
announcement - icon

Get Started with Apache Maven:

Download the E-book

eBook – Persistence – NPI EA (cat=Persistence)
announcement - icon

Working on getting your persistence layer right with Spring?

Explore the eBook

eBook – RwS – NPI EA (cat=Spring MVC)
announcement - icon

Building a REST API with Spring?

Download the E-book

Course – LS – NPI EA (cat=Jackson)
announcement - icon

Get started with Spring and Spring Boot, through the Learn Spring course:

>> LEARN SPRING
Course – RWSB – NPI EA (cat=REST)
announcement - icon

Explore Spring Boot 3 and Spring 6 in-depth through building a full REST API with the framework:

>> The New “REST With Spring Boot”

Course – LSS – NPI EA (cat=Spring Security)
announcement - icon

Yes, Spring Security can be complex, from the more advanced functionality within the Core to the deep OAuth support in the framework.

I built the security material as two full courses - Core and OAuth, to get practical with these more complex scenarios. We explore when and how to use each feature and code through it on the backing project.

You can explore the course here:

>> Learn Spring Security

Course – LSD – NPI EA (tag=Spring Data JPA)
announcement - icon

Spring Data JPA is a great way to handle the complexity of JPA with the powerful simplicity of Spring Boot.

Get started with Spring Data JPA through the guided reference course:

>> CHECK OUT THE COURSE

Partner – Moderne – NPI EA (cat=Spring Boot)
announcement - icon

Refactor Java code safely — and automatically — with OpenRewrite.

Refactoring big codebases by hand is slow, risky, and easy to put off. That’s where OpenRewrite comes in. The open-source framework for large-scale, automated code transformations helps teams modernize safely and consistently.

Each month, the creators and maintainers of OpenRewrite at Moderne run live, hands-on training sessions — one for newcomers and one for experienced users. You’ll see how recipes work, how to apply them across projects, and how to modernize code with confidence.

Join the next session, bring your questions, and learn how to automate the kind of work that usually eats your sprint time.

Course – LJB – NPI EA (cat = Core Java)
announcement - icon

Code your way through and build up a solid, practical foundation of Java:

>> Learn Java Basics

Course – LJU – NPI (tag = JUnit)
announcement - icon

Master the most popular testing framework for Java, through the Learn JUnit course:

>> LEARN JUNIT

1. Introduction

The purpose of web automation in Java is simple. In essence, the idea is to open a browser and interact with a web page. However, an immediate challenge appears from the browser itself, namely, the binary compatibility. To elaborate, each browser requires a corresponding driver binary, and that binary must match the installed browser version. Even a small mismatch leads to runtime errors. WebDriverManager in Java addresses this issue by automating driver management in Java-based Selenium projects.

In this tutorial, we’ll introduce WebDriverManager. First, we’ll explore the purpose and need for this driver. Subsequently, we’ll look at how to include WebDriverManager in the code. Lastly, we’ll discuss integrating WebDriverManager with different libraries.

2. What Is WebDriverManager?

WebDriverManager is a Java library that automatically resolves, downloads, and configures browser drivers required by Selenium. Instead of manually managing binaries and system properties, the library handles these steps programmatically. It determines which browser version is installed, finds the correct driver version, downloads it if necessary, and configures the system so Selenium can use it.

Notably, Selenium includes a built-in tool called Selenium Manager, which also automates driver management. Selenium Manager removes the need to manually download browser drivers. However, WebDriverManager is an enhanced alternative with additional features, such as driver caching control, support for Dockerized browsers, and flexibility in complex environments.

A traditional Selenium setup requires explicitly specifying the driver path in the code. For instance, for a Chrome browser, we set the driver using setProperty:

System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver");
WebDriver driver = new ChromeDriver();

This approach works initially but doesn’t scale well. Every time the browser updates, the corresponding driver should also be updated manually. In shared environments such as CI/CD pipelines or team projects, maintaining consistent driver versions becomes difficult. Moreover, hardcoded paths make the code less portable across systems.

In addition, WebDriverManager removes this burden by handling driver resolution dynamically. It also caches downloaded drivers locally, so repeated executions don’t trigger unnecessary downloads. As a result, test execution becomes both faster and more reliable.

To use WebDriverManager, we should include it as a dependency in the XML file.

For Maven, we use the <dependency> tag:

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

For Gradle, we use dependencies:

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

This ensures the library is available during test execution without affecting production builds.

3. Using WebDriverManager

In this example, we look at a basic way to use WebDriverManager for a simple call:

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

public class SimpleWebDriver {

     public static void main(String[] args) {

          WebDriverManager.chromedriver().setup();

          WebDriver driver = new ChromeDriver();
          driver.get("https://google.com");

          driver.quit();
}
}

In the example above, WebDriverManager.chromedriver() creates a manager instance specifically for Chrome. This instance hides all logic required to handle ChromeDriver binaries.

To explain the code further, calling .setup() triggers the resolution process:

    1. Inspect the system to detect the installed Chrome version.
    2. Determine the compatible driver version.
    3. Download the correct driver version if not already cached.
    4. Set the appropriate system property webdriver.chrome.driver.

Because of this, the subsequent line of ChromeDriver() works without any manual configuration.

In addition, driver.get() opens the desired URL, and driver.quit() closes the browser and releases resources.

4. Using WebDriverManager With Different Libraries

In this section, we explore how WebDriverManager integrates with JUnit for structured test execution and how it supports multiple browsers through a consistent interface. Furthermore, we also explore how it extends into more advanced use cases such as generic driver instantiation and browser detection.

4.1. Using WebDriverManager With JUnit

In professional test environments, it’s considered best practice to perform setup operations once per test class rather than repeating them before every individual test. WebDriverManager fits into this pattern when combined with JUnit 5’s @BeforeAll annotation:

import io.github.bonigarcia.wdm.WebDriverManager;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class GoogleTest {

    @BeforeAll
    static void setupClass() {
        WebDriverManager.chromedriver().setup();
    }

    @Test
    void testGoogle() {
        WebDriver driver = new ChromeDriver();
        driver.get("https://www.google.com");
        driver.quit();
    }
}

The @BeforeAll annotation guarantees that the setupClass() method is executed exactly once before any test methods in the class run. By calling WebDriverManager.chromedriver().setup() at this stage, the framework downloads and configures the correct ChromeDriver binary ahead of time, so that later tests don’t need to repeat this process. This avoids redundant driver resolution for each test case. Once the setup is complete, each individual test method can focus on browser interactions, navigating to a URL, and quitting the driver.

4.2. Working With Multiple Browsers

One of the strengths of WebDriverManager is its ability to manage drivers for multiple browsers using the same consistent pattern. Rather than writing separate setup logic for each browser, the library provides dedicated manager methods that follow an identical structure regardless of which browser is being targeted:

// Firefox
WebDriverManager.firefoxdriver().setup();
WebDriver driver = new org.openqa.selenium.firefox.FirefoxDriver();

// Microsoft Edge
WebDriverManager.edgedriver().setup();
WebDriver driver = new org.openqa.selenium.edge.EdgeDriver();

Each method returns a browser-specific manager object that handles the resolution and configuration of the appropriate driver binary for that browser.

4.3. Generic Manager Usage

One of the scenarios for generic manager usage is when we don’t know the type of target browser at compile time.

For example, when the browser type is passed as a runtime parameter, or it is read from a configuration file, we use WebDriverManager to determine the appropriate manager dynamically:

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

public class GenericExample {
    public static void main(String[] args) {
        WebDriverManager.getInstance(ChromeDriver.class).setup();

        WebDriver driver = new ChromeDriver();
        driver.get("https://example.com");
        driver.quit();
    }
}

In the code above, the getInstance(ChromeDriver.class) call accepts a driver class as its argument and uses it to identify and return the correct manager at runtime. This means the same line of code can resolve the manager for any supported browser simply by swapping out the class reference. In practice, this is useful in parameterized or data-driven test frameworks where the browser type is injected from an external source.

5. Conclusion

In this article, we began with a basic introduction to WebDriverManager. We also discussed how to use this driver for Selenium automation. Lastly, we explored how to use this driver with various libraries.

To conclude, WebDriverManager simplifies Selenium automation by eliminating manual driver management. Instead of handling downloads, version compatibility, and configuration, projects can rely on a single method call to perform all setup tasks. This assists in maintaining a clean code, fewer runtime errors, and improved maintainability.

The source code is available over on GitHub.

Baeldung Pro – NPI EA (cat = Baeldung)
announcement - icon

Baeldung Pro comes with both absolutely No-Ads as well as finally with Dark Mode, for a clean learning experience:

>> Explore a clean Baeldung

Once the early-adopter seats are all used, the price will go up and stay at $33/year.

eBook – HTTP Client – NPI EA (cat=HTTP Client-Side)
announcement - icon

The Apache HTTP Client is a very robust library, suitable for both simple and advanced use cases when testing HTTP endpoints. Check out our guide covering basic request and response handling, as well as security, cookies, timeouts, and more:

>> Download the eBook

eBook – Java Concurrency – NPI EA (cat=Java Concurrency)
announcement - icon

Handling concurrency in an application can be a tricky process with many potential pitfalls. A solid grasp of the fundamentals will go a long way to help minimize these issues.

Get started with understanding multi-threaded applications with our Java Concurrency guide:

>> Download the eBook

eBook – Java Streams – NPI EA (cat=Java Streams)
announcement - icon

Since its introduction in Java 8, the Stream API has become a staple of Java development. The basic operations like iterating, filtering, mapping sequences of elements are deceptively simple to use.

But these can also be overused and fall into some common pitfalls.

To get a better understanding on how Streams work and how to combine them with other language features, check out our guide to Java Streams:

>> Join Pro and download the eBook

eBook – Persistence – NPI EA (cat=Persistence)
announcement - icon

Working on getting your persistence layer right with Spring?

Explore the eBook

Course – LS – NPI EA (cat=REST)

announcement - icon

Get started with Spring Boot and with core Spring, through the Learn Spring course:

>> CHECK OUT THE COURSE

Partner – Moderne – NPI EA (tag=Refactoring)
announcement - icon

Modern Java teams move fast — but codebases don’t always keep up. Frameworks change, dependencies drift, and tech debt builds until it starts to drag on delivery. OpenRewrite was built to fix that: an open-source refactoring engine that automates repetitive code changes while keeping developer intent intact.

The monthly training series, led by the creators and maintainers of OpenRewrite at Moderne, walks through real-world migrations and modernization patterns. Whether you’re new to recipes or ready to write your own, you’ll learn practical ways to refactor safely and at scale.

If you’ve ever wished refactoring felt as natural — and as fast — as writing code, this is a good place to start.

eBook Jackson – NPI EA – 3 (cat = Jackson)