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:
Create chromerdriver instance:
WebDriver driver = new ChromeDriver();
get() method to open your project URL:
driver.get("https://www.google.co.in/");
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
How to set up WebDriverManager in your Selenium Maven project?
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.
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:
Comments
Post a Comment