WebDriverManager Documentation
repository·master·Indexed 25 days ago
https://github.com/bonigarcia/webdrivermanagerAn open-source Java library that automates the management of Selenium WebDriver executables, including downloading, setup, and maintenance. It supports direct WebDriver instantiation via create(), running browsers within Docker containers with VNC and recording capabilities, and providing a standalone CLI and Server for driver resolution. Features include a Java Agent for automatic driver resolution, BrowserWatcher for monitoring, and support for various browsers including Chrome, Firefox, Edge, Opera, and Internet Explorer.
What's inside WebDriverManager
- WebDriverManager uses SLF4J for logging. You can configure the output and verbosity of WebDriverManager logs by integrating SLF4J with a provider like Logback in your project.
Install WebDriverManager via Maven or Gradle
masterWebDriverManager is primarily used as a Java dependency. It is recommended to use a build tool like Maven or Gradle to manage the dependency, typically within the
testscope.### Maven ```xml <dependency> <groupId>io.github.bonigarcia</groupId> <artifactId>webdrivermanager</artifactId> <version>{project-version}</version> <scope>test</scope> </dependency>Gradle
dependencies { testImplementation("io.github.bonigarcia:webdrivermanager:{project-version}") }Inspect Dockerized Browsers via VNC and Video Recording
masterTo visualize tests running in Docker, you can enable VNC or Video Recording:
- VNC: Use
enableVnc()to start a VNC server in the container. Access the session via the URL provided bygetDockerNoVncUrl(). - Video Recording: Use
enableRecording()to record the session using FFmpeg. The MP4 file is saved in the project root by default. UsegetDockerRecordingPath()to find the file.
- VNC: Use
Start the WebDriverManager Server
masterYou can run the WebDriverManager Server using a Fat-JAR, from source code, or via a Docker container. The server provides a REST-like API to resolve drivers and can act as a Selenium Hub.Get Community Support for WebDriverManager
masterIf you need assistance with WebDriverManager, you can use the following channels:
- StackOverflow: Ask questions using the
webdrivermanager_javatag. - GitHub Issues: Report bugs, suggest improvements, or ask questions on the GitHub issues page.
- Pull Requests: Contribute enhancements via GitHub pull requests.
- StackOverflow: Ask questions using the
Automate driver management with setup()
masterUse WebDriverManager to automatically download, setup, and maintain Selenium drivers (like
chromedriver,geckodriver, ormsedgedriver). To use this, select a specific manager via the API (e.g.,chromedriver()) and call thesetup()method. This prepares the driver executable on your system so you can instantiate the standard SeleniumWebDriverobject manually.import org.junit.jupiter.api.BeforeAll; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import io.github.bonigarcia.wdm.WebDriverManager; class ChromeTest { WebDriver driver; @BeforeAll static void setupAll() { WebDriverManager.chromedriver().setup(); } @BeforeEach void setup() { driver = new ChromeDriver(); } @AfterEach void teardown() { driver.quit(); } @Test void test() { // Your test logic here } }Run browsers in Docker containers
masterWebDriverManager 5+ allows you to run browsers inside Docker containers. This requires a running Docker Engine on your machine. By combining
browserInDocker()withcreate(), WebDriverManager will pull the necessary image from Docker Hub, start the container, and return theWebDriverobject. You can also enable remote access vianoVNCusingenableVnc()and session recording usingenableRecording().import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.openqa.selenium.WebDriver; import io.github.bonigarcia.wdm.WebDriverManager; class DockerChromeVncTest { WebDriver driver; WebDriverManager wdm = WebDriverManager.chromedriver().browserInDocker() .enableVnc().enableRecording(); @BeforeEach void setup() { driver = wdm.create(); } @AfterEach void teardown() { wdm.quit(); } @Test void test() { // Your test logic here } }Use WebDriverManager as a Java Agent
masterThe WebDriverManager Agent uses the JVM instrumentation API to intercept calls and resolve drivers automatically before Selenium WebDriver objects (like
ChromeDriver) are instantiated. This removes the need for explicitWebDriverManager.chromedriver().setup()calls in your code.To configure the agent, specify the path to the WebDriverManager fat-JAR using the JVM flag
-javaagent.-javaagent:/path/to/webdrivermanager-{project-version}-fat.jarConfigure WebDriverManager via Java API, System Properties, or Environment Variables
masterWebDriverManager supports three configuration methods. The preference order (if overlapping) is:
- Environment Variables (e.g.,
WDM_CACHEPATH) - Java System Properties (e.g.,
-Dwdm.cachePath) - Java API (e.g.,
.cachePath("..."))
To convert a configuration key to an environment variable: convert to uppercase and replace
.with_.- Environment Variables (e.g.,
Troubleshoot: HTTP 403 Forbidden (GitHub Rate Limits)
masterIf you encounter an
HTTP 403error when requesting drivers hosted on GitHub (likegeckodriveroroperadriver), it is likely due to GitHub's traffic rate limits.Solutions:
- Use a GitHub Personal Access Token: Configure a token to make authenticated requests. Use the
gitHubToken(String)API method or theGITHUB_TOKENenvironment variable. - WebDriverManager 5.3.0+: As of version 5.3.0, this issue is largely mitigated because WebDriverManager uses a GitHub Actions mirror for API responses instead of querying GitHub directly.
- Use a GitHub Personal Access Token: Configure a token to make authenticated requests. Use the
Troubleshoot: Connectivity and Proxy Issues
masterIn corporate environments with proxies or firewalls, WebDriverManager may fail to download drivers.
Solution: Use the proxy capabilities to configure your connection:
WebDriverManager.chromedriver().proxy("myproxy:port").setup();Troubleshoot: Chromedriver 115+ Support
masterStarting with chromedriver 115, releases are no longer published via traditional repositories but via Chrome for Testing (CfT) JSON endpoints. Older versions of WebDriverManager will fail with a
404error.Solution:
- Upgrade: Bump WebDriverManager to the latest version (5.4+ implements CfT support).
- Clear Cache: To ensure old, incorrect versions are not used from the resolution cache, run:
WebDriverManager.chromedriver().clearDriverCache().setup();