WebDriverManager or System.setProperty()?
Who this post is for:
- Anyone who wants to do automation testing on Selenium
Deciding which browser for testing is the first step in automating tests. Specifying the system properties and initializing the browser object is really important. As you know Google Chrome browser, Firefox Browser, Internet Explorer, etc. are some of the browsers. And drivers are the bridges between test scripts and browsers. First download the binary files of these drivers like chromedriver, geckodriver, etc. If we want to launch any of browser's drivers for testing, we need to set the executable path. After that, initialize the driver and move forward with the code you want to execute. This is the traditional way of instantiating browsers. All these steps are troublesome anymore as we need to apply these every time when the versions changed. Therefore we use the “WebDriverManager” class.
The setProperty method has two attributes: “propertyName” and “value.” The propertyName represents the name of the browser-specific driver, and the value points to the path of that browser driver.
Look at my example which shows the usage of setProperty
When new binaries or new browser versions are released, we need to check the compatibility for each executable once again and then repeat the process if there are compatibility issues. This process of downloading manually the executables, setting their paths, then executing the scripts is time-consuming and inefficient. WebdriverManager is an open-source personal project of an independent contributor named Boni Garcia.
How can we add the dependency of WebDriverManager?
You need to look at https://github.com/bonigarcia/webdrivermanager-examples to find more examples or better understanding.
Look at my example which shows the usage of WebDriverManager
What is the benefits of WebDriverManager class in Selenium?
1.Automates the management of WebDriver binaries.
2.Downloads the appropriate driver binaries, if not already present, into the local cache.
3.Downloads the latest version of the browser binary, unless otherwise specified.
4.Eliminates the need to store driver binaries locally. We also need not maintain various versions of the binary driver files for different browsers.
How to use a specific WebDriver and Browser version?
Let’s say, the latest chromedriver version is 91.0 (released on 2021–04–22). But if you want an earlier version, let’s say, Chromedriver version 88.0, you need to add the below code.
Same as the WebDriver version, you can define the browser version also. You need to add the below code.
I hope you understood and liked it! See you on my next blog. You can leave a comment or directly contact me via LinkedIn
Thanks a lot!
References: https://github.com/bonigarcia/webdrivermanager and