The secret behind webdrivermanager

I am planning to discuss the technical implementation and the usage of the webdrivermanager in this article.

I have written an Intro article on webdrivermanager, including the current status of the project. Highly recommended to read it before this.

First let’s take a look at how to use this in our project.

You can initialize the webdriver using three different ways provided by the webdrivermanager.

  • Adding WebDriverManager.Xdriver().setup(); where you want to initialize the webdriver where X will be different browsers. If you are supporting different browsers, you need to setup a driver for each browser as below.
WebDriverManager.chromedriver().setup();
WebDriverManager.firefoxdriver().setup();
WebDriverManager.edgedriver().setup();
WebDriverManager.operadriver().setup();
WebDriverManager.phantomjs().setup();
WebDriverManager.iedriver().setup();
WebDriverManager.chromiumdriver().setup();
  • Via the generic driver manager which can be parameterized using Selenium driver classes such as org.openqa.selenium.chrome.ChromeDriver, org.openqa.selenium.firefox.FirefoxDriver and so on.
import org.openqa.selenium.chrome.ChromeDriver;....Class<? extends WebDriver> driverClass = ChromeDriver.class;
WebDriverManager.getInstance(driverClass).setup();
WebDriver driver = driverClass.newInstance();
  • Using the DriverManagerType
DriverManagerType chrome = DriverManagerType.CHROME;
WebDriverManager.getInstance(chrome).setup();
Class<?> chromeClass = Class.forName(chrome.browserClass());
WebDriver driver = (WebDriver) chromeClass.newInstance();

You should be curious to find what’s really happening behind the stage.

First it check the version of the browser installed on the machine and then matches with the version of the driver. In case the matching driver was not available in uses the latest driver available.

Once all these versioning issues resolved, then checks if the driver is available on the WebDriverManager cache, otherwise it downloads the driver. Finally, exports the proper Webdriver java environment variables required by Selenium for the execution.

Webdrivermanager provides an API for the users leverage on to fine tune the executions and to provide better feedback in logs and reports. I will keep that to a separate article and below is the official github project where you can get more info.

Have fun !

Thanks for reading!

I hope you found this article useful! If you have any questions feel free to add a response. If you like it feel free to clap and share with your community.

Tech Enthusiast | Test Automation Consultant | Nature Lover | Hiker | Writer | Grower

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store