WebDriverManager

What is WebDriverManager? WebDriverManager is an open-source Java library that carries out the management (i.e., download, setup, and maintenance) of the drivers required by Selenium WebDriver (e.g., chromedriver, geckodriver, msedgedriver, etc.) in a fully automated manner. In addition, as of version 5, WebDriverManager provides other relevant features, such as the capability to discover browsers installed in the local system, building WebDriver objects (such as ChromeDriver, FirefoxDriver, EdgeDriver, etc.), and running browsers in Docker containers seamlessly. Selenium WebDriver is a library that allows controlling web browsers programmatically. It provides a cross-browser API that can be used to drive web browsers (e.g., Chrome, Edge, or Firefox, among others) using different programming languages (e.g., Java, JavaScript, Python, C#, or Ruby). The primary use of Selenium WebDriver is implementing automated tests for web applications. WebDriverManager is primarily used as a Java dependency (although other usages are also possible). We typically use a build tool (such as Maven or Gradle) to resolve the WebDriverManager dependency. In Maven, it can be done as follows (notice that it is declared using the test scope, since it is typically used in tests classes): io.github.bonigarcia webdrivermanager 5.0.3 test The primary use of WebDriverManager is the automation of driver management. For using this feature, you need to select a given manager in the WebDriverMager API (e.g., chromedriver() for Chrome) and invoke the method setup(). The following example shows a test case using JUnit 5, Selenium WebDriver, WebDriverManager, and AssertJ (for fluent assertions). In this test, we invoke WebDriverManager in the setup method for all tests (@BeforeAll). This way, the required driver (chromedriver) will be available for all the WebDriver tests using Chrome in this class. import static org.assertj.core.api.Assertions.assertThat; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import io.github.bonigarcia.wdm.WebDriverManager; class ChromeTest { WebDriver driver; @BeforeAll static void setupClass() { WebDriverManager.chromedriver().setup(); } @BeforeEach void setupTest() { driver = new ChromeDriver(); } @AfterEach void teardown() { driver.quit(); } @Test void test() { // Exercise driver.get("https://bonigarcia.dev/selenium-webdriver-java/"); String title = driver.getTitle(); // Verify assertThat(title).contains("Selenium WebDriver"); } } WebDriverManager provides a set managers for Chrome, Firefox, Edge, Opera, Chromium, and Internet Explorer. The basic use of these managers is the following: WebDriverManager.chromedriver().setup(); WebDriverManager.firefoxdriver().setup(); WebDriverManager.edgedriver().setup(); WebDriverManager.operadriver().setup(); WebDriverManager.chromiumdriver().setup() WebDriverManager.iedriver().setup(); ref: https://bonigarcia.dev/webdrivermanager/