Skip to content

OperaDriver is a vendor-supported WebDriver implementation developed by Opera and volunteers that enables programmatic automation of different Opera products. It is a part of the Selenium project.

License

lachlanhunt/operadriver

 
 

Repository files navigation

OperaDriver

OperaDriver is a vendor-supported WebDriver implementation developed by Opera and volunteers that enable programmatic automation of different Opera products. It is a part of the Selenium project.

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.

Documentation

Getting started

To get set up, first download either 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 OperaDriver instance:

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 org.openqa.selenium.*, and com.opera and artifact ID operadriver for OperaDriver specifically.

Other languages

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:4444", DesiredCapabilities.opera());
driver.get("http://opera.com/");

Capabilities

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 Opera-specific capabilities supported are:

Capability Type Default Description
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.product OperaProduct/String Desktop The product to request, for example OperaProduct#DESKTOP or OperaProduct#MOBILE. It will attempt to locate the product binary based on the operating system's default installation paths if opera.binary is not set.
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 -help for available command-line switches.
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.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.

OperaDriver also supports some of the common desired capabilities too:

Custom profile

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 custom profile:

DesiredCapabilities capabilities = DesiredCapabilities.opera();

OperaProfile profile = new OperaProfile("/path/to/profile");  // prepared profile
capabilities.setCapability("opera.profile", profile);

WebDriver driver = new OperaDriver(capabilities);

Opera Mobile Emulator

Or to tell the Opera Mobile Emulator to use the tablet UI and a specific screen resolution:

DesiredCapabilities capabilities = DesiredCapabilities.opera();

capabilities.setCapability("opera.product", OperaProduct.MOBILE);
capabilities.setCapability("opera.arguments", "-tabletui -displaysize 860x600");

WebDriver driver = new OperaDriver(capabilities);

Logging and X display

Similarly, to increase the logging verbosity and, for GNU/Linux, 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);

Proxy

It is also possible to configure a proxy for use with Opera. The proxy configuration is set through the capabilities. You can use the Proxy helper in Selenium to manage it:

DesiredCapabilities capabilities = DesiredCapabilities.opera();

Proxy proxy = new Proxy();
proxy.setHttpProxy("127.0.0.1:1234");
capabilities.setCapability("proxy", proxy);

WebDriver driver = new OperaDriver(capabilities);

Environment variables

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:

Name Description
OPERA_PATH The absolute path to the Opera binary you want to use. If not set OperaDriver will try to locate an Opera (desktop or mobile) 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 or operamobile -help to see available arguments.

To set environment variables:

  • GNU/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

Desktop

This is a list of the official Opera Desktop versions supported by OperaDriver:

Version Workaround/tweaks needed
12.50
12.01
12.00
11.64
11.62
11.61
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

Mobile

(Not released yet.)

Wrapper script

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

Development

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.

Support

If you have problems or questions regarding OperaDriver or Selenium, there are many channels in which you can seek help:

  • IRC: The #selenium channel on the irc.freenode.org network
  • Mailing lists: The webdriver or selenium-users mailing list

About

OperaDriver is a vendor-supported WebDriver implementation developed by Opera and volunteers that enables programmatic automation of different Opera products. It is a part of the Selenium project.

Resources

License

Stars

Watchers

Forks

Packages

No packages published