OperaDriver Is Now a Part of Selenium and Has Experimental Android Support

A bit of background

Back in early 2009, when I started working on OperaWatir, WebDriver was announced, and it looked very interesting with its really compact API. I started talking with Simon Stewart, "the WebDriver guy" and decided it would be great if we could support both the (Ruby-based) Watir and (Java-based) WebDriver APIs. JRuby, a Java implementation of the Ruby programming language, allowed us to connect the two, using OperaDriver as the back-end for OperaWatir.

The work on the current codebase started in February 2009, and we had a first working prototype in March 2009, which we announced on the Core blog. Soon thereafter, we started using OperaDriver internally for testing our Opera Presto engine. A public release took a bit longer, as the Scope protocol got a big change from XML to protobuff and was mostly rewritten. In February of this year, we then released OperaDriver and OperaWatir as open source projects.

What is OperaDriver?

OperaDriver is Opera's WebDriver implementation that follows the standard WebDriver API, which has recently become Selenium 2. It supports Opera browsers on desktop, mobile and even on devices. It uses a network protocol using protocol buffers and is a standalone package that you can directly use.

Testing benefits

Since we followed the WebDriver specifications, tests written for other browsers (such as Firefox, Chrome or Internet Explorer) should work out of the box with OperaDriver (to be correct, there are some exceptions involving browser specific APIs, but these are rather rare). Using OperaDriver you can automate the testing of your web application, run it through multiple browsers, and get back results with JUnit or your choice of test framework.

Ongoing testing framework standardization

A while back, the WebDriver and Selenium projects merged, with Watir joining as watir-webdriver. Similar to OperaWatir using OperaDriver as a back-end, watir-webdriver is using WebDriver to power browser driving. This ongoing standardization effort is going to make test automation of web applications and browsers a breeze, and we are very proud to have been a part of this effort from the start.

Worth noting in this context is that Selenium 2 RC3 came out on Monday, and it has built-in support for Opera!

Driving Opera Mobile on Android

As an added bonus, we're releasing our Android launcher, which is in its alpha stages. To use it, you need the Android SDK. Follow the instructions below to automate testing on Opera Mobile running on Android phones and tablets. The launcher allows you to start/stop Opera and also supports typing (note that there are some known bugs related to timing issues, especially in Android 3.0).

Below you can find instructions for Mac. Please replace USERNAME with your actual username.

Preparation:

  1. Download the Android SDK from http://developer.android.com/sdk/index.html and install it to e.g. /Developer
  2. Download Eclipse (Classic is fine) from http://www.eclipse.org/downloads/ and install it.
  3. Connect your Android phone with a USB cable to your computer and turn on USB debugging on the phone.
  4. Make sure your phone and computer are connected to the same Wi-Fi network

Installing the shepherd-release.apk

  1. Download release.zip to your desktop and unzip it to /Users/USERNAME/Desktop/release
  2. Open Terminal and do /Developer/android-sdk-mac_x86/tools/adb install /Users/USERNAME/Desktop/release/shepherd-release.apk - confirm the installation is a success.

Eclipse

  1. Start Eclipse
  2. Go to File > New > Java Project, type in a name (e.g. TestProject) and click Finish
  3. Right-click on TestProject and go to Properties
  4. Select Java Build Path from the sidebar, go to the Libraries tab and click Add External JARs...
  5. Navigate to /Users/USERNAME/Desktop/release/webdriver-opera , select all .jar files in that folder and click Open, then OK.
  6. Right-click on TestProject, go to New > Class
  7. Type in AndroidTest and click Finish
  8. Inside AndroidTest.java, replace the content with the following:
    import com.opera.core.systems.OperaDriver;
    import com.opera.core.systems.settings.OperaDriverSettings;
    
    public class AndroidTest {
    
    	public static void main(String[] args) throws Exception {
    		OperaDriverSettings settings = new OperaDriverSettings();
    		settings.setAndroid(true);
    		settings.setAdbPath("/Developer/android-sdk-mac_x86/tools/adb");
    		settings.setOperaLauncherHost("127.0.0.1"); // replace with your current IP
    		settings.setOperaLauncherListeningPort(9999);
    		OperaDriver driver = new OperaDriver(settings);
    		driver.closeAll(); // required due to a bug in window-manager
    		driver.get("http://www.google.no/m");
    		driver.findElementById("homepage_query_box_textbox").sendKeys("Opera");
    		driver.findElementById("homepage_query_box_submit").click();
    		Thread.sleep(5000); // sleep so we can see the results
    		driver.quit();
    	}
    }
    
  9. Replace 127.0.0.1 with your local network IP address, which you can find via the ifconfig command in the terminal, or under Network in System Preferences.
  10. Click on the Run button to execute the test. Save changes when prompted. The test will open Opera Mobile, go to the Google Mobile site for Norway, type Opera, search for it, wait 5 seconds and then close the browser.

I would like to thank Opera's Dev Tools team for their support during this project, and Andreas for his help with the blog post.