org.openqa.selenium.chrome
Class ChromeDriver

java.lang.Object
  extended by org.openqa.selenium.remote.RemoteWebDriver
      extended by org.openqa.selenium.chrome.ChromeDriver
All Implemented Interfaces:
org.openqa.selenium.HasCapabilities, org.openqa.selenium.HasInputDevices, org.openqa.selenium.internal.FindsByClassName, org.openqa.selenium.internal.FindsByCssSelector, org.openqa.selenium.internal.FindsById, org.openqa.selenium.internal.FindsByLinkText, org.openqa.selenium.internal.FindsByName, org.openqa.selenium.internal.FindsByTagName, org.openqa.selenium.internal.FindsByXPath, org.openqa.selenium.JavascriptExecutor, org.openqa.selenium.SearchContext, org.openqa.selenium.TakesScreenshot, org.openqa.selenium.WebDriver

public class ChromeDriver
extends RemoteWebDriver
implements org.openqa.selenium.TakesScreenshot

A WebDriver implementation that controls a Chrome browser running on the local machine. This class is provided as a convenience for easily testing the Chrome browser. The control server which each instance communicates with will live and die with the instance.

To avoid unnecessarily restarting the ChromeDriver server with each instance, use a RemoteWebDriver coupled with the desired ChromeDriverService, which is managed separately. For example:

 
 import static org.junit.Assert.assertEquals;
 
 import org.junit.After;
 import org.junit.AfterClass;
 import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.runner.RunWith;
 import org.junit.runners.BlockJUnit4ClassRunner
 import org.openqa.selenium.chrome.ChromeDriverService;
 import org.openqa.selenium.remote.DesiredCapabilities;
 import org.openqa.selenium.remote.RemoteWebDriver;
 
 @RunWith(BlockJUnit4ClassRunner.class)
 public class ChromeTest extends TestCase {
 
   private static ChromeDriverService service;
   private WebDriver driver;
 
   @BeforeClass
   public static void createAndStartService() {
     service = new ChromeDriverService.Builder()
         .usingChromeDriverExecutable(new File("path/to/my/chromedriver.exe"))
         .usingAnyFreePort()
         .build();
     service.start();
   }
 
   @AfterClass
   public static void createAndStopService() {
     service.stop();
   }
 
   @Before
   public void createDriver() {
     driver = new RemoteWebDriver(service.getUrl(),
         DesiredCapabilities.chrome());
   }
 
   @After
   public void quitDriver() {
     driver.quit();
   }
 
   @Test
   public void testGoogleSearch() {
     driver.get("http://www.google.com");
     WebElement searchBox = driver.findElement(By.name("q"));
     searchBox.sendKeys("webdriver");
     searchBox.quit();
     assertEquals("webdriver - Google Search", driver.getTitle());
   }
 }
 
 

See Also:
ChromeDriverService.createDefaultService()

Nested Class Summary
 
Nested classes/interfaces inherited from class org.openqa.selenium.remote.RemoteWebDriver
RemoteWebDriver.RemoteTargetLocator, RemoteWebDriver.RemoteWebDriverOptions, RemoteWebDriver.When
 
Nested classes/interfaces inherited from interface org.openqa.selenium.WebDriver
org.openqa.selenium.WebDriver.ImeHandler, org.openqa.selenium.WebDriver.Navigation, org.openqa.selenium.WebDriver.Options, org.openqa.selenium.WebDriver.TargetLocator, org.openqa.selenium.WebDriver.Timeouts, org.openqa.selenium.WebDriver.Window
 
Constructor Summary
ChromeDriver()
          Creates a new ChromeDriver using the default server configuration.
ChromeDriver(org.openqa.selenium.Capabilities capabilities)
          Creates a new ChromeDriver instance.
ChromeDriver(ChromeDriverService service)
          Creates a new ChromeDriver instance.
ChromeDriver(ChromeDriverService service, org.openqa.selenium.Capabilities capabilities)
          Creates a new ChromeDriver instance.
ChromeDriver(ChromeDriverService service, ChromeOptions options)
          Creates a new ChromeDriver instance with the specified options.
ChromeDriver(ChromeOptions options)
          Creates a new ChromeDriver instance with the specified options.
 
Method Summary
<X> X
getScreenshotAs(org.openqa.selenium.OutputType<X> target)
           
 void setFileDetector(FileDetector detector)
           
 
Methods inherited from class org.openqa.selenium.remote.RemoteWebDriver
close, execute, execute, executeAsyncScript, executeScript, findElement, findElement, findElementByClassName, findElementByCssSelector, findElementById, findElementByLinkText, findElementByName, findElementByPartialLinkText, findElementByTagName, findElementByXPath, findElements, findElements, findElementsByClassName, findElementsByCssSelector, findElementsById, findElementsByLinkText, findElementsByName, findElementsByPartialLinkText, findElementsByTagName, findElementsByXPath, get, getCapabilities, getCommandExecutor, getCurrentUrl, getElementConverter, getErrorHandler, getExecuteMethod, getFileDetector, getKeyboard, getMouse, getPageSource, getSessionId, getTitle, getWindowHandle, getWindowHandles, log, manage, navigate, quit, setCommandExecutor, setElementConverter, setFoundBy, setLogLevel, setSessionId, startClient, startSession, startSession, stopClient, switchTo, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ChromeDriver

public ChromeDriver()
Creates a new ChromeDriver using the default server configuration.

See Also:
ChromeDriver(ChromeDriverService, ChromeOptions)

ChromeDriver

public ChromeDriver(ChromeDriverService service)
Creates a new ChromeDriver instance. The service will be started along with the driver, and shutdown upon calling RemoteWebDriver.quit().

Parameters:
service - The service to use.
See Also:
ChromeDriver(ChromeDriverService, ChromeOptions)

ChromeDriver

public ChromeDriver(org.openqa.selenium.Capabilities capabilities)
Creates a new ChromeDriver instance. The capabilities will be passed to the chromedriver service.

Parameters:
capabilities - The capabilities required from the ChromeDriver.
See Also:
ChromeDriver(ChromeDriverService, Capabilities)

ChromeDriver

public ChromeDriver(ChromeOptions options)
Creates a new ChromeDriver instance with the specified options.

Parameters:
options - The options to use.
See Also:
ChromeDriver(ChromeDriverService, ChromeOptions)

ChromeDriver

public ChromeDriver(ChromeDriverService service,
                    org.openqa.selenium.Capabilities capabilities)
Creates a new ChromeDriver instance. The service will be started along with the driver, and shutdown upon calling RemoteWebDriver.quit().

Parameters:
service - The service to use.
capabilities - The capabilities required from the ChromeDriver.

ChromeDriver

public ChromeDriver(ChromeDriverService service,
                    ChromeOptions options)
Creates a new ChromeDriver instance with the specified options. The service will be started along with the driver, and shutdown upon calling RemoteWebDriver.quit().

Parameters:
service - The service to use.
options - The options to use.
Method Detail

setFileDetector

public void setFileDetector(FileDetector detector)
Overrides:
setFileDetector in class RemoteWebDriver

getScreenshotAs

public <X> X getScreenshotAs(org.openqa.selenium.OutputType<X> target)
Specified by:
getScreenshotAs in interface org.openqa.selenium.TakesScreenshot


Copyright © 2012. All Rights Reserved.