Tuesday, 9 August 2022

Automation of web driver | Usage of WebDriverManager or alternative for System.setProperty("webdriver.chrome.driver", "D\chromedriver.exe");

  • 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 driver or from the project path. 
More details : 

GitHub @ https://github.com/bonigarcia/webdrivermanager

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");

Now, using DriverMnager we can get rid of physical drive path, that is replace the above line of code with 

This requires the following dependency to be added in pom.xml file. 

<!-- https://mvnrepository.com/artifact/io.github.bonigarcia/webdrivermanager -->

In the Before hook of cucumber, normally we create the ChromeDriver object, prior creating the chrome driver object, we need to call the chrome driver setup() as shown in below example.

@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");		
	driver = new ChromeDriver();