public class OperaDriver extends RemoteWebDriver implements LocationContext, 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.WhenWebDriver.ImeHandler, WebDriver.Navigation, WebDriver.Options, WebDriver.TargetLocator, WebDriver.Timeouts, WebDriver.Window| Constructor and Description |
|---|
OperaDriver()
Creates a new OperaDriver using the
default
server configuration. |
OperaDriver(Capabilities capabilities)
Creates a new OperaDriver instance.
|
OperaDriver(OperaDriverService service)
Creates a new OperaDriver instance.
|
OperaDriver(OperaDriverService service,
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 |
|---|---|
LocalStorage |
getLocalStorage() |
SessionStorage |
getSessionStorage() |
Location |
location()
Gets the physical location of the browser.
|
void |
setFileDetector(FileDetector detector)
Set the file detector to be used when sending keyboard input.
|
void |
setLocation(Location location)
Sets the physical 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, getRemoteStatus, getScreenshotAs, getSessionId, getTitle, 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(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, 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)
RemoteWebDriversetFileDetector in class RemoteWebDriverdetector - The detector to use. Must not be null.FileDetector,
LocalFileDetector,
UselessFileDetectorpublic LocalStorage getLocalStorage()
getLocalStorage in interface WebStoragepublic SessionStorage getSessionStorage()
getSessionStorage in interface WebStoragepublic Location location()
LocationContextlocation in interface LocationContextLocation containing the location information. Returns null if the location is
not availablepublic void setLocation(Location location)
LocationContextsetLocation in interface LocationContextlocation - A Location containing the new location information