Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run Selenium WebDriver test cases in Chrome

People also ask

Does Selenium WebDriver work with Chrome?

Through WebDriver, Selenium supports all major browsers on the market such as Chrome/Chromium, Firefox, Internet Explorer, Edge, Opera, and Safari.

What driver is must to run tests in Chrome driver?

Webdriver driver = New ChromeDriver(); The main motto of the ChromeDriver is to launch Google Chrome. Without that, it is not possible to execute Selenium test scripts in Google Chrome browser. This is the main reason why you need ChromeDriver to run test cases on Google Chrome browser.


You need to download the executable driver from: ChromeDriver Download

Then use the following before creating the driver object (already shown in the correct order):

System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver");
WebDriver driver = new ChromeDriver();

This was extracted from the most useful guide from the ChromeDriver Documentation.


Download the updated version of the Google Chrome driver from Chrome Driver.

Please read the release note as well here.

If the Chrome browser is updated, then you need to download the new Chrome driver from the above link, because it would be compatible with the new browser version.

public class chrome
{

    public static void main(String[] args) {

        System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver");
        WebDriver driver = new ChromeDriver();

        driver.get("http://www.google.com");
    }

}

You should download the chromeDriver in a folder, and add this folder in your PATH environment variable.

You'll have to restart your console to make it work.


If you're using Homebrew on a macOS machine, you can use the command:

brew tap homebrew/cask && brew cask install chromedriver

It should work fine after that with no other configuration.