How to run Selenium WebDriver test cases in Chrome

I tried this

WebDriver driver = new ChromeDriver();

But I'm getting the error as

Failed tests: setUp(com.TEST): The path to the driver executable must be set by the webdriver.chrome.driver system property; for more information, see code here . The latest version can be downloaded from this link

How can I make Chrome test the Selenium WebDriver test cases?


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.