public class OperaDriver extends RemoteWebDriver implements org.openqa.selenium.html5.LocationContext, org.openqa.selenium.html5.WebStorage
WebDriver implementation that controls a Blink-based Opera 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 OperaDriver server with each instance, use a
RemoteWebDriver coupled with the desired OperaDriverService, which is managed
separately. For example:
import static org.junit.Assert.assertEquals;
import org.junit.*;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.openqa.selenium.opera.OperaDriverService;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
{@literal @RunWith(JUnit4.class)}
public class OperaTest extends TestCase {
private static OperaDriverService service;
private WebDriver driver;
{@literal @BeforeClass}
public static void createAndStartService() {
service = new OperaDriverService.Builder()
.usingDriverExecutable(new File("path/to/my/operadriver.exe"))
.usingAnyFreePort()
.build();
service.start();
}
{@literal @AfterClass}
public static void createAndStopService() {
service.stop();
}
{@literal @Before}
public void createDriver() {
driver = new RemoteWebDriver(service.getUrl(),
DesiredCapabilities.opera());
}
{@literal @After}
public void quitDriver() {
driver.quit();
}
{@literal @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());
}
}
Note that unlike OperaDriver, RemoteWebDriver doesn't directly implement
role interfaces such as LocationContext and WebStorage.
Therefore, to access that functionality, it needs to be
augmented and then cast
to the appropriate interface.RemoteWebDriver.RemoteTargetLocator, RemoteWebDriver.RemoteWebDriverOptions, RemoteWebDriver.Whenorg.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 and Description |
|---|
OperaDriver()
Creates a new OperaDriver using the
default
server configuration. |
OperaDriver(org.openqa.selenium.Capabilities capabilities)
Creates a new OperaDriver instance.
|
OperaDriver(OperaDriverService service)
Creates a new OperaDriver instance.
|
OperaDriver(OperaDriverService service,
org.openqa.selenium.Capabilities capabilities)
Creates a new OperaDriver instance.
|
OperaDriver(OperaDriverService service,
OperaOptions options)
Creates a new OperaDriver instance with the specified options.
|
OperaDriver(OperaOptions options)
Creates a new OperaDriver instance with the specified options.
|
| Modifier and Type | Method and Description |
|---|---|
org.openqa.selenium.html5.LocalStorage |
getLocalStorage() |
org.openqa.selenium.html5.SessionStorage |
getSessionStorage() |
org.openqa.selenium.html5.Location |
location() |
void |
setFileDetector(FileDetector detector) |
void |
setLocation(org.openqa.selenium.html5.Location location) |
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, getScreenshotAs, getSessionId, getTitle, getW3CStandardComplianceLevel, getWindowHandle, getWindowHandles, log, manage, navigate, quit, setCommandExecutor, setElementConverter, setErrorHandler, setFoundBy, setLogLevel, setSessionId, startClient, startSession, startSession, stopClient, switchTo, toStringpublic OperaDriver()
default
server configuration.public OperaDriver(OperaDriverService service)
service will be started along with the driver,
and shutdown upon calling RemoteWebDriver.quit().service - The service to use.OperaDriver(OperaDriverService, OperaOptions)public OperaDriver(org.openqa.selenium.Capabilities capabilities)
capabilities will be passed to the
chromedriver service.capabilities - The capabilities required from the OperaDriver.OperaDriver(OperaDriverService, Capabilities)public OperaDriver(OperaOptions options)
options - The options to use.OperaDriver(OperaDriverService, OperaOptions)public OperaDriver(OperaDriverService service, OperaOptions 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.public OperaDriver(OperaDriverService service, org.openqa.selenium.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 OperaDriver.public void setFileDetector(FileDetector detector)
setFileDetector in class RemoteWebDriverpublic org.openqa.selenium.html5.LocalStorage getLocalStorage()
getLocalStorage in interface org.openqa.selenium.html5.WebStoragepublic org.openqa.selenium.html5.SessionStorage getSessionStorage()
getSessionStorage in interface org.openqa.selenium.html5.WebStoragepublic org.openqa.selenium.html5.Location location()
location in interface org.openqa.selenium.html5.LocationContextpublic void setLocation(org.openqa.selenium.html5.Location location)
setLocation in interface org.openqa.selenium.html5.LocationContextCopyright © 2016. All rights reserved.