|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.openqa.selenium.remote.RemoteWebDriver
org.openqa.selenium.chrome.ChromeDriver
public class ChromeDriver
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.
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());
}
}
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 |
---|
WebDriver.ImeHandler, WebDriver.Navigation, WebDriver.Options, WebDriver.TargetLocator, WebDriver.Timeouts, WebDriver.Window |
Constructor Summary | |
---|---|
ChromeDriver()
Creates a new ChromeDriver using the default
server configuration. |
|
ChromeDriver(Capabilities capabilities)
Deprecated. Use ChromeDriver(ChromeOptions) instead. |
|
ChromeDriver(ChromeDriverService service)
Creates a new ChromeDriver instance. |
|
ChromeDriver(ChromeDriverService service,
Capabilities capabilities)
Deprecated. Use ChromeDriver(ChromeDriverService, ChromeOptions) |
|
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 | ||
---|---|---|
|
getScreenshotAs(OutputType<X> target)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public ChromeDriver()
default
server configuration.
ChromeDriver(ChromeDriverService, ChromeOptions)
public ChromeDriver(ChromeDriverService service)
service
will be started along with the driver,
and shutdown upon calling RemoteWebDriver.quit()
.
service
- The service to use.ChromeDriver(ChromeDriverService, ChromeOptions)
@Deprecated public ChromeDriver(Capabilities capabilities)
ChromeDriver(ChromeOptions)
instead.
capabilities
will be passed to the
chromedriver service.
capabilities
- The capabilities required from the ChromeDriver.ChromeDriver(ChromeDriverService, Capabilities)
public ChromeDriver(ChromeOptions options)
options
- The options to use.ChromeDriver(ChromeDriverService, ChromeOptions)
@Deprecated public ChromeDriver(ChromeDriverService service, Capabilities capabilities)
ChromeDriver(ChromeDriverService, ChromeOptions)
service
will be started along with the
driver, and shutdown upon calling RemoteWebDriver.quit()
.
service
- The service to use.capabilities
- The capabilities required from the ChromeDriver.public ChromeDriver(ChromeDriverService service, ChromeOptions options)
service
will be
started along with the driver, and shutdown upon calling RemoteWebDriver.quit()
.
service
- The service to use.options
- The options to use.Method Detail |
---|
public <X> X getScreenshotAs(OutputType<X> target)
getScreenshotAs
in interface TakesScreenshot
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |