- Notifications
You must be signed in to change notification settings - Fork682
Automated driver management and other helper features for Selenium WebDriver in Java
License
bonigarcia/webdrivermanager
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
WebDriverManager is an open-source Java library that carries out the management (i.e., download, setup, and maintenance) of the drivers required bySelenium WebDriver (e.g., chromedriver, geckodriver, msedgedriver, etc.) in a fully automated manner. In addition, WebDriverManager provides other relevant features, such as the capability to discover browsers installed in the local system, building WebDriver objects (such asChromeDriver
,FirefoxDriver
,EdgeDriver
, etc.), and running browsers in Docker containers seamlessly.
As of version 5, the documentation of WebDriverManager has movedhere. This site contains all the features, examples, configuration, and advanced capabilities of WebDriverManager.
The primary use of WebDriverManager is the automation of driver management. For using this feature, you need to select a given manager in the WebDriverManager API (e.g.,chromedriver()
for Chrome) and invoke the methodsetup()
. The following example shows the skeleton of a test case usingJUnit 5,Selenium WebDriver, andWebDriverManager.
importorg.junit.jupiter.api.AfterEach;importorg.junit.jupiter.api.BeforeAll;importorg.junit.jupiter.api.BeforeEach;importorg.junit.jupiter.api.Test;importorg.openqa.selenium.WebDriver;importorg.openqa.selenium.chrome.ChromeDriver;importio.github.bonigarcia.wdm.WebDriverManager;classChromeTest {WebDriverdriver;@BeforeAllstaticvoidsetupAll() {WebDriverManager.chromedriver().setup(); }@BeforeEachvoidsetup() {driver =newChromeDriver(); }@AfterEachvoidteardown() {driver.quit(); }@Testvoidtest() {// Your test logic here }}
Alternatively, you can use the methodcreate()
to manage automatically the driver and instantiate theWebDriver
object in a single line. For instance, as follows:
importorg.junit.jupiter.api.AfterEach;importorg.junit.jupiter.api.BeforeEach;importorg.junit.jupiter.api.Test;importorg.openqa.selenium.WebDriver;importorg.openqa.selenium.chrome.ChromeDriver;importio.github.bonigarcia.wdm.WebDriverManager;classChromeCreateTest {WebDriverdriver;@BeforeEachvoidsetup() {driver =WebDriverManager.chromedriver().create(); }@AfterEachvoidteardown() {driver.quit(); }@Testvoidtest() {// Your test logic here }}
For further information about the driver resolution algorithm implemented by WebDriverManager and configuration capabilities, read thedocumentation.
Another relevant new feature available in WebDriverManager 5 is the ability to create browsers inDocker containers out of the box. The requirement to use this feature is to have installed aDocker Engine in the machine running the tests. To use it, we need to invoke the methodbrowserInDocker()
in conjunction withcreate()
of a given manager. This way, WebDriverManager pulls the image fromDocker Hub, starts the container, and instantiates the WebDriver object to use it. The following test shows a simple example using Chrome in Docker. This example also enables the recording of the browser session and remote access usingnoVNC:
importorg.junit.jupiter.api.AfterEach;importorg.junit.jupiter.api.BeforeEach;importorg.junit.jupiter.api.Test;importorg.openqa.selenium.WebDriver;importio.github.bonigarcia.wdm.WebDriverManager;classDockerChromeVncTest {WebDriverdriver;WebDriverManagerwdm =WebDriverManager.chromedriver().browserInDocker() .enableVnc().enableRecording();@BeforeEachvoidsetup() {driver =wdm.create(); }@AfterEachvoidteardown() {wdm.quit(); }@Testvoidtest() {// Your test logic here }}
WebDriverManager is part ofOpenCollective, an online funding platform for open and transparent communities. You can support the project by contributing as a backer (i.e., a personaldonation orrecurring contribution) or as asponsor (i.e., a recurring contribution by a company).
Alternatively, you can acknowledge my work by buying me a coffee:
WebDriverManager (Copyright © 2015-2025) is a project created and maintained byBoni Garcia and licensed under the terms of theApache 2.0 License.
About
Automated driver management and other helper features for Selenium WebDriver in Java