Before using Selenium, we need to make sure we already have a driver that matches the browser version under test, if not, we have to go ahead to the official website and download the driver we need. However, the browsers are updated so frequently in nowdays, downloading drivers become frequent, so it turns to be a chore. If you’re running in hub-node mode with many browsers, this is even more uncomfortable.
I recently found a project which can solve these problems well.
Function
WebDriverManager
has the following functions:
- Automatically download the required version of the
driver
- Save setting the environment variable for the driver path, that is, no need to write explicitly
System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe")
Usage
pom.xml
For Maven project with JDK 8+
1 | <dependency> |
in tests
Before new driver()
, do setting like this:
1 | WebDriverManager.chromedriver().setup(); |
The drivers managers for various browsers can be used as follows:
1 | WebDriverManager.chromedriver().setup(); |
But sometimes we want the process of creating a driver to be adaptable to different browsers, ie parameterized, which can be like this:
1 | import static io.github.bonigarcia.wdm.DriverManagerType.CHROME; |
More details
The above is only the most basic and useful functions for me, WebDriverManager
has still many other rich features, such as:
- Set proxy
- Set agent
- Set specific browser and driver version
- and so on…
For more information, please visit the offical website WebDriverManager