Reputation: 3959
In my pom
script I have:
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.53.1</version>
</dependency>
The repository description on MVNrepository lists several compile dependencies, including Selenium-Chrome-Driver, Selenium-Firefox-Driver, etc. I can run Firefox-Driver scripts successfully but when I attempt to run the same script using the object
ChromeDriver driver = new ChromeDriver();
I get the following error:
java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.chrome.driver system property; for more information, see https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver. The latest version can be downloaded from http://chromedriver.storage.googleapis.com/index.html
It works without having to download Firefox-Driver (that's the point of the pom
script); is it different for Chrome-Driver? The image below shows that it's being compiled from the Maven script.
The test script:
import org.junit.Test;
import org.openqa.selenium.chrome.ChromeDriver;
import static org.junit.Assert.assertTrue;
public class MyFirstTest {
@Test
public void googleTest() {
ChromeDriver driver = new ChromeDriver();
driver.get("https://www.google.com/");
assertTrue(driver.getTitle().equals("Google"));
driver.quit();
}
}
Upvotes: 0
Views: 1360
Reputation: 13970
Yes, it's different from Firefox, and the difference is explained on a page referenced by exception:
The ChromeDriver consists of three separate pieces. There is the browser itself ("chrome"), the language bindings provided by the Selenium project ("the driver") and an executable downloaded from the Chromium project which acts as a bridge between "chrome" and the "driver". This executable is called "chromedriver", but we'll try and refer to it as the "server" in this page to reduce confusion.
So in order to instantiate ChromeDriver, you need to
Specify its path when instantiating the driver (or else, have it defined in PATH
). For example:
System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver");
ChromeDriver driver = new ChromeDriver();
All various options on how to specify ChromeDriver binary are discussed here.
Chrome itself should have a defined location, so that ChromeDriver finds it. How to do that is explained here
Upvotes: 1