This page documents how to start using ChromeDriver for testing your website on desktop (Windows/Mac/Linux). You can also read Getting Started with Android or Getting Started with ChromeOS SetupChromeDriver is a separate executable that Selenium WebDriver uses to control Chrome. It is maintained by the Chromium team with help from WebDriver contributors. If you are unfamiliar with Selenium WebDriver, you should check out the Selenium site. Follow these steps to setup your tests for running with ChromeDriver:
ChromeDriver expects you to have Chrome installed in the default location for your platform. You can also force ChromeDriver to use a custom location by setting a special capability.
Any of these steps should do the trick: Sample testJava: import org.openqa.selenium.*; import org.openqa.selenium.chrome.*; import org.junit.Test; public class GettingStarted { @Test public void testGoogleSearch() throws InterruptedException { // Optional. If not specified, WebDriver searches the PATH for chromedriver. System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver"); WebDriver driver = new ChromeDriver(); driver.get("http://www.google.com/"); Thread.sleep(5000); // Let the user actually see something! WebElement searchBox = driver.findElement(By.name("q")); searchBox.sendKeys("ChromeDriver"); searchBox.submit(); Thread.sleep(5000); // Let the user actually see something! driver.quit(); } } Python: import time Controlling ChromeDriver's lifetimeThe ChromeDriver class starts the ChromeDriver server process at creation and terminates it when quit is called. This can waste a significant amount of time for large test suites where a ChromeDriver instance is created per test. There are two options to remedy this: 1. Use the ChromeDriverService. This is available for most languages and allows you to start/stop the ChromeDriver server yourself. See here for a Java example (with JUnit 4): import java.io.*; import org.junit.*; import org.openqa.selenium.*; import org.openqa.selenium.chrome.*; import org.openqa.selenium.remote.*; public class GettingStartedWithService { private static ChromeDriverService service; private WebDriver driver; @BeforeClass public static void createAndStartService() throws IOException { service = new ChromeDriverService.Builder() .usingDriverExecutable(new File("/path/to/chromedriver")) .usingAnyFreePort() .build(); service.start(); } @AfterClass public static void stopService() { service.stop(); } @Before public void createDriver() { driver = new RemoteWebDriver(service.getUrl(), new ChromeOptions()); } @After public void quitDriver() { driver.quit(); } @Test public void testGoogleSearch() { driver.get("http://www.google.com"); // rest of the test... } } Python: import time 2. Start the ChromeDriver server separately before running your tests, and connect to it using the Remote WebDriver. Terminal: $ ./chromedriver Java: import java.net.*; import org.openqa.selenium.*; import org.openqa.selenium.chrome.*; import org.openqa.selenium.remote.*; public class GettingStartedRemote { public static void main(String[] args) throws MalformedURLException { WebDriver driver = new RemoteWebDriver( new URL("http://127.0.0.1:9515"), new ChromeOptions()); driver.get("http://www.google.com"); driver.quit(); } } |