WebDriverManager in Selenium
Before we begin, Let’s understand what is WebDriverManager ?
WebDriverManager is a Java Library that helps in driver management required for Selenium.
It carries out driver management actions such as download, setup & maintenance.
It is a open-source Library supports for drivers like, chromedriver (Chrome Browser) , geckodriver ( for Firefox Browser) ,msedgedriver ( for Edge Browser), etc.
Setup
We Typically use 2 types of build management tools for Selenium project i.e. Maven & Gradle.
To download WebDriverManager dependencies for a Build, we need to include below line of code into the build file.
- Maven
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>5.1.1</version>
</dependency>
- Gradle
implementation group: ‘io.github.bonigarcia’, name: ‘webdrivermanager’, version: ‘5.1.1’
Latest version can be checked from, https://mvnrepository.com/artifact/io.github.bonigarcia/webdrivermanager
- you may also include .jar file for webdrivermanager to the project, Just in case if you are not familiar with the build tools.
How to instantiate Browser using WebDriverManager ?
we need to add below line of code to test, (this will set the chrome driver for the test). It has Automated way to download the required Binaries/.exe files.
Below line will check the latest version of specified driver binary is available on the machine or node. If it’s not present then it will download it.
WebDriverManager.chromedriver().setup();
Once you have downloaded the required binary(.exe) file for driver. we need to create the Object of specific browser using below line of code.
WebDriver driver = new ChromeDriver();
Above line will instantiate the Selenium Webdriver instance to the ChromeDriver.
Example:
Below line of code is simple example of how to use WebDriverManager in Tests.
In the above code,
- We have imported required classes using import statements.
- Created a WebDriverManager instance using WebDriveManager.chromedriver.setup();
- Created driver instance for chromedriver
- Navigated to https://www.google.com using driver.get() method.
- At the end, quit the driver instance.
Hope you have liked the topic and will try to implement it in your project !
Keep Learning !!!
hit the follow button for more topics on Java, RestAssured, GraphQL, Selenium, JavaScript, JUnit, Jenkins, GitHub Actions, WebUI, SOAP & VBScripts
Also, DM me if you want me to add new topic of your choice urgently.