QA Talks Community
3 min readAug 29, 2021

--

WebDriverManager: To Manage Browser Drivers Easily and Efficiently

Why Web Driver Manager?

To run our Selenium WebDriver automation scripts on Chrome / Firefox browsers, we must download the binary/.exe files like Chromedriver.exe and geckodriver.exe.

Later we need to set the path of these files in our script like below or its location should be added to the classpath.

Error if the path is not set correctly:

The path to the driver executable must be set by the webdriver.chrome.driver system property.

Manually downloading and managing these drivers for each operating system is very painful. We also must check when new versions of the binaries are released / new browsers versions are released. We should check the compatibility for all the executables and add them.

To overcome this drawback of manually maintaining these binaries and setting path in scripts WebDriverManager by Boni Garcia does this for you in an automated way without manually checking the new versions and maintaining binaries for all browsers.

What is Web Driver Manager?

WebDriverManager is an API that allows users to automate the handling of driver executables like chromedriver.exe, geckodriver.exe etc required by Selenium WebDriver API.

This helps us to avoid all the manual steps that we previously had to do, related to browser driver setup, in order to run our tests.

It supports browsers such as Chrome, Firefox, Opera, PhantomJS, Microsoft Edge, or Internet Explorer.

Maven Dependency for WebDriverManager

In the Maven project, we need to add the below dependency into pom.xml

Chrome Code Snippet for WebDriverManager:

public class WebDriverManagerChrome{@Testpublic void webDriverManagerChrome(){WebDriverManager.chromedriver().setup();WebDriver driver = new ChromeDriver();driver.manage().window().maximize();driver.manage().deleteAllCookies();driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);driver.get("https://classic.crmpro.com/index.html");}}

In above code WebDriverManager.chromedriver().setup(); is a magic statement which actually does following work:

1. It checks the version of the browser installed in your machine (e.g. Chrome, Firefox).

2. It checks the version of the driver (e.g. chromedriver, geckodriver). If unknown, it uses the latest version of the driver.

3. It downloads the WebDriver binary if it is not present on the WebDriverManager cache (~/.m2/repository/webdriver by default).

4. It exports the proper WebDriver Java environment variables required by Selenium (not done when using WebDriverManager from the CLI or as a Server).

WebDriverManager downloads the driver binaries for the browsers Chrome, Firefox, Opera, PhantomJS, Microsoft Edge, Internet Explorer, and Chromium. For that, it provides several drivers managers for these browsers. These drivers managers can be used as follows:

1. WebDriverManager.chromedriver().setup();

2. WebDriverManager.firefoxdriver().setup();

3. WebDriverManager.operadriver().setup();

4. WebDriverManager.phantomjs().setup();

5. WebDriverManager.edgedriver().setup();

6. WebDriverManager.iedriver().setup();

7. WebDriverManager.chromiumdriver().setup();

When we use WebDriverManager, by default, it tries to download the latest version of a given driver binary.

if you want to use a specific version of driver, we can do that by using

WebDriverManager.chromedriver().version(“2.40”).setup();

You can force WebDriverManager to download specific versions by changing the value of the variables in webdrivermanager.properties for wdm.chromeDriverVersion,wdm.operaDriverVersion, wdm.internetExplorerDriverVersion, or wdm.edgeDriverVersion to a concrete version.

I hope you found this blog useful. Please let me know your inputs in the comments section.

Author:

more blogs…

--

--

QA Talks Community

Welcome to QA Talks, a community-based startup that's mainly focused on QA blogs & talks — https://www.tech-talks.info/