How to launch the chrome browser without chromedriver.exe (only for Maven)

Selenium WebDriver is the most used automation tool these days. Selenium WebDriver interacts with different browsers like Chrome, Firefox, and Internet Explorer to run various types of tests. In short Selenium WebDriver is a popular automation tool for cross-browser testing.

Cross-browser automation testing requires Selenium to interact with the browser for which the script is to be run. To interact browser, you must download the driver.exe file according to the browser.

Example: You want to run your automation script in the Chrome browser. So you have to download the chromedriver.exe file into your local system and then you have to set the path of that chromedriver.exe to your automation script.

set chromedriver.exe path:

String driverPath= "write here your chromeDriver path";
System.setProperty("webdriver.chrome.driver", System.getProperty("user.dir")+pathDriver);

Create chromerdriver instance:

WebDriver driver = new ChromeDriver();

get() method to open your project URL:

driver.get("https://www.google.co.in/");

The above code will open the chrome browser using chromedriver.exe and open the google site. Every time you have to maintain the browser driver according to the browser version. Thus maintaining the browser driver manually is time consuming and difficult, yes or no?

Definitely yes guys. So what is the solution?

Dr. Boni Garcia found the best solution and gave us the webdrivermanager.

What is WebDriverManager?

WebDriverManager is an open source Java library. 

How is it working?

WebDriverManager runs a resolution algorithm to automate the process for the correct driver binary. WebDrivermanager performs four steps when you run your scripts.

  • Find
  • Download
  • Setup
  • Maintenance
It detects the browser driver version according to your browser version, downloads it, sets it in your project's libraries and maintains the browser driver when you run your automation scripts.

How to set up WebDriverManager in your Selenium Maven project?

Setting up WebDriverManager in a Maven project is very easy. Go to mvnrepository from your Chrome browser and search for Webdrivermanager. 
(Link: https://mvnrepository.com/artifact/io.github.bonigarcia/webdrivermanager/5.3.2)




















From the results you get, click on io.github.bonigarcia » webdrivermanager.


You will find different versions of WebDriverManager Click on one of the versions.


Copy the contents of the dependency shown.


Dependency:
<!-- https://mvnrepository.com/artifact/io.github.bonigarcia/webdrivermanager -->
<dependency>
    <groupId>io.github.bonigarcia</groupId>
    <artifactId>webdrivermanager</artifactId>
    <version>5.3.2</version>
</dependency>

Copy and paste the dependencies into the pom.xml file of your Maven project and save pom.xml. After you save the pom.xml, you will find the browser driver jar files automatically downloaded in your project's Maven dependencies folder. The WebDriverManager library provides the WebDriverManager class and the static methods of this class create managers to manage browser drivers.

Below are the managers that will manage the drivers of different browsers.

WebDriverManager.chromedriver().setup();

WebDriverManager.chromiumdriver().setup();

WebDriverManager.firefoxdriver().setup();

WebDriverManager.edgedriver().setup();

WebDriverManager.iedriver().setup();

WebDriverManager.operadriver().setup();

WebDriverManager.safaridriver().setup();

Now if you want to open chrome browser then you have to use chrome browser driver.

WebDriverManager.chromedriver().setup();
WebDriver driver = new ChromeDriver();

Now let's understand with a simple test case example.

package com.practices.org;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.Test;
import io.github.bonigarcia.wdm.WebDriverManager;
public class LaunchChromeBrowser {

@Test
public void launchChromeBrowser() {

// WebDriverManager --> ChromeDriver --> setup()
WebDriverManager.chromedriver().setup();
WebDriver driver = new ChromeDriver();

// To maximize browser window
driver.manage().window().maximize();

// To launch your project URL
driver.get("https://www.google.co.in/");

// To close browser
driver.close();

}
}

Conclusion: 

In this blog we learned that you can easily manage browsers drivers with the help of 
the WebDriverManager without downloading browser drivers.

Comments

Popular posts from this blog

Generate Stunning HTML and Allure Reports with Playwright in TypeScript

Handle bootstrap date picker using selenium java

How to Take a Screenshot of a Webpage Using Selenium WebDriver in Java?