WebDriver is a general purpose library for automating web browsers. It can drive the browser running various tests on your web pages, just as if a real user was navigating through them. It can emulate actions like clicking links, enter text and submitting forms, and reporting 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 without tedious manual testing routines.
OperaDriver is usable out of the box from the official Selenium packages, and can be used no extra setup on any modern version of Opera.
- API documentation
- Selenium WebDriver documentation
- Java examples
- Python bindings API
- Ruby bindings API
- Complete list of capabilities
To get set up, first
the selenium-server-standalone or selenium-server package and make
sure you have a fairly recent version of Opera installed in a default
location. Finally, all you need to do is create a new
WebDriver driver = new OperaDriver(); driver.get("http://opera.com/");
If you prefer using a package management system, OperaDriver is also
available through Maven; either as a part of the Selenium package, or
as a separate package. The group ID for Selenium is
com.opera and artifact ID
operadriver for OperaDriver
Since WebDriver provides bindings for several programming languages, you can follow the same approach as above in both Python (using the selenium package) and in Ruby (using the selenium-webdriver gem).
The Python equivalent of the above example would be:
from selenium import webdriver driver = webdriver.Opera() driver.get('http://opera.com/')
The same in Ruby:
require 'selenium-webdriver' driver = Selenium::WebDriver.for :opera driver.get('http://opera.com/')
To execute the tests, please ensure that the environmental variable SELENIUM_SERVER_JAR contains the path to the selenium-server-standalone JAR you downloaded earlier.
To execute the Python test:
SELENIUM_SERVER_JAR=/path/to/selenium-server-standalone.jar python test.py
And for Ruby:
SELENIUM_SERVER_JAR=/path/to/selenium-server-standalone.jar ruby test.rb
Running the server as a standalone process
OperaDriver is fully compatible with the RemoteWebDriver client. This allows you to run tests on a remote computer which is typically very useful in a distributed environment. First, ensure that your Selenium server is running, then create a remote client as usual:
WebDriver driver = new RemoteWebDriver("http://localhost:9515", DesiredCapabilities.opera()); driver.get("http://opera.com/");
To customize Opera and WebDriver in various ways you may request a certain configuration from the Selenium server. Since not all server implementations supports every WebDriver feature, the client and server should use JSON objects with the properties when describing which features are desirable.
In additon to the general WebDriver capabilities available, OperaDriver has a number of custom capabilities that may be requested. To request a specific driver configuration you
You can use the DesiredCapabilities class to request a specific driver configuration. The capabilities supported by OperaDriver are:
|opera.logging.level||Level/String/Integer||Level.INFO||(String/Level/Integer) How verbose the logging should be. Available levels are: SEVERE (highest value), WARNING, INFO, CONFIG, FINE, FINER, FINEST (lowest value), ALL, OFF.
The argument may consist of either a level name as a string, an integer value, a Level reference, or null. If the value is neither of a known name nor an integer, an IllegalArgumentException will be thrown.
|opera.logging.file||File/String||null||Where to send the output of the logging. Default is to not write to file.|
|opera.binary||String||Default location of Opera on system||Path to the Opera binary to use. If not specified, OperaDriver will guess the path to your Opera installation (typically /usr/bin/opera, C:\Program Files\Opera\opera.exe, or similar).|
|opera.arguments||String||null||Arguments to pass to Opera, separated by spaces. See
|opera.host||String||Non-loopback IP if available, loopback otherwise||The host Opera should connect to. Since OperaDriver works in a client-server relationship to Opera (where Opera is the client, driver the server) you can also run remote instances of Opera on other devices; that be a phone, a TV or another computer.|
|opera.port||Integer||Random port||The port to Opera should connect to. Setting this capability to 0 will probe for a free, random port, setting it to -1 will ensure compatibility mode using port the default port 7001 for Operas version 11.52 or older.|
|opera.profile||OperaProfile/string||temporary profile||directory of the profile to use, or an OperaProfile instance object representing a profile. if null is given, a random temporary directory is used. if "", an empty string, then the default ~/.autotest profile directory will be used (for backwards compatibility with opera < 11.60).|
|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 host/port information, and hit Connect to connect manually.|
|opera.detach||Boolean||false||Whether to detach the Opera browser when the driver shuts down. This will leave Opera running.|
|opera.display||Integer||null||The X display to use. If set, Opera will be started on the specified display. (Only works on GNU/Linux.)|
|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 with great accuracy tell 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.product||OperaProduct/String||Desktop||The product we are using, for example
|opera.launcher||String||null||Path to the launcher binary to use. The launcher is an external wrapper around the browser, and is used for controlling the binary and taking external screenshots. If left blank, OperaDriver will use a launcher supplied with the package.|
For instance the OperaDriver can be made to start the browser with
specific command-line arguments using the
opera.arguments key. This
key should define a list of a command-line arguments that should be
passed to the browser on startup. For example, to start Opera with a
OperaProfile profile = new OperaProfile(); // fresh, temporary profile profile.preferences().set("User Prefs", "Ignore Unrequested Popups", false); DesiredCapabilities capabilities = DesiredCapabilities.opera(); capabilities.setCapability("opera.profiel", profile); WebDriver driver = new OperaDriver(capabilities);
Similarly, to set up more detailed logging and, for GNU/Linux, send ask Opera to start on a different X display:
DesiredCapabilities capabilities = DesiredCapabilities.opera(); capabilities.setCapability("opera.logging.level", Level.CONFIG); capabilities.setCapability("opera.logging.file", "/var/log/operadriver.log"); capabilities.setCapability("opera.display", 8); WebDriver driver = new OperaDriver(capabilities);
To specify a custom location of the Opera binary and the command-line arguments to use, you may also use environmental variables. These are the available variables:
|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.
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
Supported Opera versions
This is a list of the official Opera Desktop versions supported by OperaDriver:
Some Opera versions don't support the
-pd arguments sent by OperaDriver by default. You can bypass
this problem by creating a wrapper script like this and pointing the
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
While OperaDriver is officially maintained by Opera, it is free software and would only be possible thanks to many volunteer contributors. If you come across a reproducible bug, please open an issue to submit a bug report.
Even better, you can send a pull request! Any changes you make must follow the Google Coding Standards and have test cases attached to them if you introduce a new feature.
Much of OperaDriver's code is shared with the other WebDriver implementations, and for working on this code base you should also familiarize yourself with the Selenium code base. There are also a few tips available for working on Selenium.
If you have problems or questions regarding OperaDriver or Selenium, there are many channels in which you can seek help: