Automation of web driver | Usage of WebDriverManager or alternative for System.setProperty("webdriver.chrome.driver", "D\chromedriver.exe");
( JasperSoft BI Suite Tutorials - Sadakar Pochampalli )
- WebDriverManager is an open-source Java library
- It carries out the management (i.e., download, setup, and maintenance) of the drivers required by Selenium WebDriver(e.g., chromedriver, geckodriver, msedgedriver, etc.) in a fully automated manner.
- The primary use of WebDriverManager is the automation of driver.
- With this we can get rid of System property to fetch the driver placed in physical drive or from the project path.
https://bonigarcia.dev/webdrivermanager/
GitHub @ https://github.com/bonigarcia/webdrivermanager
Example:
This is how we set the path for chrome driver once the driver is downloaded and placed in system hard drive .
System.setProperty("webdriver.chrome.driver", "D\chromedriver.exe");
Example:
This is how we set the path for chrome driver once the driver is downloaded and placed in system hard drive .
Now, using DriverMnager we can get rid of physical drive path, that is replace the above line of code with
WebDriverManager.chromedriver().setup();
This requires the following dependency to be added in pom.xml file.
<!-- https://mvnrepository.com/artifact/io.github.bonigarcia/webdrivermanager -->
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>4.3.0</version>
</dependency>
@Before(order = 0) // Cucumber Before Hook with order 0
public void before(Scenario scenario) throws IOException {
Log.info("Initiating the chrome driver from Cucumber Before hook with order=0");
WebDriverManager.chromedriver().setup();
driver = new ChromeDriver();
driver.manage().window().maximize();
}