|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
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.
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());
}
}
ChromeDriverService.createDefaultService()
Nested Class Summary |
---|
Nested classes/interfaces inherited from class org.openqa.selenium.remote.RemoteWebDriver |
---|
RemoteWebDriver.RemoteTargetLocator, RemoteWebDriver.RemoteWebDriverOptions |
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)
Creates a new ChromeDriver instance. |
|
ChromeDriver(ChromeDriverService service)
Creates a new ChromeDriver instance. |
|
ChromeDriver(ChromeDriverService service,
Capabilities capabilities)
Creates a new ChromeDriver instance. |
Method Summary | ||
---|---|---|
|
getScreenshotAs(OutputType<X> target)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ChromeDriver()
default
server configuration.
ChromeDriver(ChromeDriverService, Capabilities)
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, Capabilities)
public ChromeDriver(Capabilities capabilities)
capabilities
will be passed to the
chromedriver service.
capabilities
- The capabilities required from the ChromeDriver.ChromeDriver(ChromeDriverService, Capabilities)
public ChromeDriver(ChromeDriverService service, Capabilities capabilities)
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.Method Detail |
---|
public <X> X getScreenshotAs(OutputType<X> target)
getScreenshotAs
in interface TakesScreenshot
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |