OperaDriver is a vendor-supported WebDriver implementation developed by Opera Software and volunteers that implements WebDriver's wire protocol.
OperaDriver can drive the browser running various tests on your web pages, just as if a real user was navigating through them. It can simulate actions like clicking links, entering text and submitting forms, and reports results back to you so you know that your website works as intended.
OperaDriver's end-user emulation ensures that your entire stack (HTML, scripts, styling, embedded resources and backend setup) is functioning correctly, and this without tedious manual testing routines.
You will need Oracle's Java Runtime Environment 1.5 or newer to use OperaDriver. It uses the Scope interface (same as for Dragonfly) to communicate directly with Opera from Java. Consequently, it is only compatible with Opera version 11.5 or newer.
The OperaDriver server expects you to have Opera installed in the default location for each system:
| OS | Expected Location of Opera |
|---|---|
| GNU/Linux | /usr/bin/opera |
| Mac | /Applications/Opera.app/Contents/MacOS/Opera |
| WIndows | %PROGRAMFILES%\Opera\opera.exe |
However, you can override this and specify a custom location to Opera by
setting the capability opera.path or environmnetal variable OPERA_PATH.
You can read more about configuring WebDriver under Advanced Usage.
Other libraries required by OperaDriver:
- Apache Commons Exec 1.1
- Apache Commons JXPath 1.3
- Google Guava 10.0.1
- Google protobuf 2.4.1
- JUnit 4.10
- Selenium 2.13.0
To use OperaDriver on Opera < 11.52, make sure you set the capabilities
opera.port to -1 and opera.profile to "" (empty string) to
disable -debugproxy and -pd command-line arguments which older
versions of Opera do not support.
To get set up please
download either
selenium-server-standalone or selenium-server and make sure you have a
fairly recent version of Opera installed. All you do is to create a new
OperaDriver instance:
WebDriver driver = new OperaDriver();
driver.navigate().to("http://opera.com/");
Since OperaDriver implements the wire protocol, it is fully compatibly with any RemoteWebDriver client. Simply start up your server, create a client, and away you go:
WebDriver driver = new RemoteWebDriver("http://localhost:9515", DesiredCapabilities.opera());
driver.navigate().to("http://opera.com/");
You can also use OperaDriver as a standalone dependency in your project. Download the package from the Github project's download section and extract it to a location of your choice. To see some examples look at the examples/ directory. For your own projects include the lib/* directory on your classpath, for example:
javac -classpath "lib/*:." Example.java
In Eclipse this can be done under Project → Properties → Java Build Path and then "Add JARs..." or "Add External JARs..." depending on the layout of your project.
You can use the DesiredCapabilities class to specify settings for OperaDriver. The capabilities we support are:
| Capability | Type | Default | Description |
|---|---|---|---|
| opera.logging.level | String | "INFO" | How verbose the logging should be. Available levels are: SEVERE (highest value), WARNING, INFO, CONFIG, FINE, FINER, FINEST (lowest value), ALL. Default is INFO. |
| opera.logging.file | String | null | Where to send the output of the logging. Default is to not write to file. |
| opera.binary | String | null | Path to the Opera binary to use. If not specified, OperaDriver will guess the path to your Opera installation. |
| opera.arguments | String | null | Arguments to pass on to Opera, separated by spaces. See opera -help for available command-line arguments. |
| opera.host | String | "127.0.0.1" | The host Opera should connect to. Unless you're starting Opera manually you won't need this. |
| opera.port | Integer | 7001 | The port Opera should connect to. 0 = Random port, -1 = Opera default (port 7001) (for use with Opera < 12). |
| opera.launcher | String | null | Absolute path to the launcher binary to use. The launcher is a gateway between OperaDriver and the Opera browser, and is being used for controlling and monitoring the binary, and taking external screenshots. If left blank, OperaDriver will use the launcher supplied with the package. |
| opera.profile | String | null | Directory to use for the Opera profile. If null a random temporary directory is used. If "", an empty string, then the default autotest profile directory is used. |
| opera.idle | Boolean | false | Whether to use Opera's alternative implicit wait implementation. It will use an in-browser heuristic to guess when a page has finished loading,allowing us to determine with great accuracy whether there are any planned events in the document. This functionality is useful for very simple test cases, but not designed for real-world testing. It is disabled by default. |
| opera.display | Integer | null | 82FEThe X display to use. (Only works on UNIX-like OSes.) |
| opera.autostart | Boolean | true | Whether to auto-start the Opera binary. If false, OperaDriver will wait for a connection from the browser. Go to "opera:debug", enter the correct port number and hit "Connect" to connect manually. |
| opera.no_restart | Boolean | false | Whether to restart. |
| opera.no_quit | Boolean | false | Whether to quit Opera when OperaDriver is shut down. If enabled, it will keep the browser running after the driver is shut down. |
| opera.guess_binary_path | Boolean | true | Whether to guess the path to Opera if it isn't set in opera.binary. |
| opera.product | String | null | The product we are using, for example "desktop" or "core-desktop", "sdk". See OperaProduct for all available values. |
To use capabilities:
DesiredCapabilities capabilities = DesiredCapabilities.opera();
capabilities.setCapability("opera.logging.level", "CONFIG");
capabilities.setCapability("opera.logging.file", "/var/log/operadriver.log");
capabilities.setCapability("opera.display", 8);
capabilities.setCapability("opera.profile", "/home/andreastt/my-own-opera-profile");
// Now use it
WebDriver driver = new OperaDriver(capabilities);
driver.navigate().to("http://opera.com/");
See also the information available on the RemoteWebDriver at the Selenium wiki.
To specify such things as a custom location of the Opera binary and the command-line arguments to use, you may use environmental variables also. This is a list of the environmental variables which can be set on any operating system:
| Name | Description |
|---|---|
| OPERA_PATH | The absolute path to the Opera binary you want to use. If not set OperaDriver will try to locate Opera on your system. |
| OPERA_ARGS | A space-delimited list of arguments to pass on to Opera, e.g. -nowindow, -dimensions 1600x1200, &c. See opera --help to view available arguments. |
| OPERA_PRODUCT | To override the product check when running the OperaDriver tests. Set this to any value specified in OperaProduct. |
To set environment variables:
- Linux and Mac:
export OPERA_PATH=..., and add this line to~/.bashrc(or your shell's configuration file) to use in all future sessions. - Windows: Please follow this guide: http://support.microsoft.com/kb/310519
This is a list of the official Opera Desktop versions supported by OperaDriver:
| Version | Workaround/tweaks needed |
|---|---|
| 12.00 | (Not released yet) |
| 11.60 | |
| 11.52 | Set opera.port to -1 and opera.profile to "" (empty string) to disable -debugproxy and -pd command-line arguments |
| 11.51 | |
| 11.50 | |
| 11.11 | |
| 11.10 | |
| 11.01 | -autotestmode command-line argument is not supported, use a wrapper script |
| 11.00 |
Some Opera versions don't support the -autotestmode, -debugproxy or -pd
arguments sent by OperaDriver by default. You can bypass this problem by
creating a wrapper script like this and pointing the capability opera.binary
to its absolute path:
#!/bin/sh
# Wrapper to prevent the -autotestmode argument reaching this version of Opera
# which doesn't support it.
`dirname $0`/opera
- Modifier keys' states are not preserved across multiple
.sendKeys()calls inActions - Problems with Operas with IME feature enabled (Opera Mobile, Android)
- No support for Opera Mini
- No support for JavaScript alert/popup dialogues
- getScreenshotAs() only returns image data of the current viewport, other parts of the image will be black.
- Requires Administrator privileges on Windows Vista and 7 when Opera 11.5x is installed in the default location (Program Files).
- Not possible to move into an image enclosed in a link
- Failing the test for clicking a button that closes an open window does not cause the browser to hang
- Failing test for getting window handles after closing a window
- Problems with coordinates on moving mouse back and forth past view port
- Closing the final browser window causes an exception