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.
No more hassle to manage web-drivers
Web driver manager will take care of managing all your drivers. Interesting! isn’t it? Alright let’s dig deep with a…
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.
- 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;
WebDriver driver = driverClass.newInstance();
- Using the DriverManagerType
DriverManagerType chrome = DriverManagerType.CHROME;
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 !
WebDriverManager is a library which allows to automate the management of the drivers (e.g. chromedriver, geckodriver…
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.