Opera Core Concerns

Official blog for Core developers at Opera

Test automation with OperaWatir

, ,

To make sure new versions of our browser core are of sufficient quality before making their way into any of our products, we run more than 100,000 automated tests on a number of different reference configurations every time we have a new build.

We run automated visual tests, JavaScript tests, selftests, performance tests, stability tests, memory tests and a lot more. One thing we have been missing, however, is automated tests for the things that require some sort of user interaction--clicking links, filling out forms, interacting with complex Web applications.

That is ... until now.

We are working on adding support for driving the browser through our scope protocol, which is the same protocol we use for the Opera Dragonfly debugger. Through a simple script, we can instruct the browser to automatically to search Google, log into Hotmail and send a message, buy books at Amazon or find plane tickets at Expedia.

Here's an example of what such a script can look like:

require "operawatir"

browser = OperaWatir::Opera.new
browser.goto("http://www.google.com")
browser.text_field(:name, "q").value = "Wikipedia"
browser.button(:name, "btnG").click

browser.link(:text, "Wikipedia").click

puts "PASS" if browser.text.include? "Wikipedia"

The syntax above is that of the Watir API, a Ruby test tool originally developed for Internet Explorer that is now being ported to Opera and other browsers.

Below is a video of the script running in the desktop version of our browser. We've had to slow it down significantly for you to be able to see what's going on - the test normally takes a few hundred milliseconds.

Through scripts like these, we can automatically test many of the things our millions of users do every day. If we break anything and a test fails, our scripts will instantly notify us so that we can fix it.

But testing these things on our x86 test builds is not enough. We ship on hundreds of different devices every year and need to run the same tests on many different platforms to make sure everything is still working after porting.

When using the scope protocol, it doesn't really matter if you're talking to an Opera instance locally or remotely; it was built for working on any device. Here's the exact same script running on a mobile phone:

Shortly after we started working on this tool, we figured that this might not just be useful for us testing our browser engine, but for Web developers testing their own Web applications, too. Our new tools are still in a pre-alpha stage, but as they mature over the coming months, we would like to make them available to all of you as well.

There are several different browser drivers out there, and we would like to support the most popular ones. The script above was using the Watir API. The following script is doing the same thing through Webdriver, which will be used in the next version of Selenium:

public class OperaDriverExample  {
    public static void main(String[] args) {
        WebDriver driver = new OperaDriver();
        driver.get("http://www.google.com");
        WebElement element = driver.findElement(By.name("q"));
        element.sendKeys("Wikipedia");
        element.submit();
        WebElement wikipediaLink = driver.findElement(By.linkText("Wikipedia"));
        wikipediaLink.click();
        System.out.println("Page title is: " + driver.getTitle());
    }
}

New in Opera Presto 2.2: TLS 1.2 SupportGeolocation-enabled build

Comments

Tamil Friday, March 6, 2009 2:43:13 PM

up

Tuttle Friday, March 6, 2009 2:55:59 PM

Nice feature.
I expect a release of this. bigsmile

sirnh1 Friday, March 6, 2009 3:01:06 PM

This sound nice. Can't wait to 'play' with it smile

Aux Friday, March 6, 2009 3:12:18 PM

<irony>I see rise of robots in theese videos. Please, destroy Watir before it is too late!</irony>

dahulevogyre Friday, March 6, 2009 3:43:52 PM

Excellent !!
I will finally be able to control the best browser in the world from my Java apps !

Fantastic !

FataL Friday, March 6, 2009 3:45:03 PM

I hope this will help you fight regressions. wait

Charles SchlossChas4 Friday, March 6, 2009 4:22:09 PM

up

Thiago H. de Paula FigueiredoThiagoHP Friday, March 6, 2009 5:44:21 PM

In what language is that script written?

dreamdrummerddrum Friday, March 6, 2009 5:48:20 PM

One thing that you have to add to this automation API, is ability to fetch the current browser viewport as a PNG. Both visible viewport area only, and also big picture with all scrollable content. Some tests need to verify pixel-by-pixel as well, and this would enable it easily.

Ravindran NavaneethanRavindran Friday, March 6, 2009 6:14:07 PM

Great !!!

serious Friday, March 6, 2009 8:30:22 PM

really cool ... you could build a macro-recording function out of this wink

Michael Johnsonpitredbeard Friday, March 6, 2009 9:30:14 PM

@ThiagoHP: The first script is in Ruby (according to the article). I'm not sure what the second is in, but there is support for Selenium in several languages.

Martin RauscherHades32 Saturday, March 7, 2009 12:55:55 PM

Great! Maybe finally people can stop screaming "Opera broke xxxxx! How can they! It's a page millions use.....bla bla" sherlock

Barraco Mármol Jerónimojerobarraco Sunday, March 8, 2009 4:05:49 AM

cool, this will set the standard of quality at a higher level.
i'm proud of opera smile
just a little question, i'm not clear about where is this code being ran.
but if its downloadable from internet a malicious script could be injected.

otherway, i rather python, but this looks just awesome.

Aleksander AasAleksander Monday, March 9, 2009 9:40:43 AM

This looks really cool.

Ice ArdorIceArdor Monday, March 9, 2009 11:41:38 AM

I used AutomatedQA's TestComplete last summer to automate our company's online backup audit service. You can use multiple scripting languages to remote control a browser, application, or anything that can be done with a mouse or keyboard. It was pretty sweet.

Wilhelm Joys Andersenwilhelmja Monday, March 9, 2009 11:49:43 AM

@FataL: That is the intention. We already run more than 100,000 automated tests, but this tool will allow us to improve our test coverage significantly.

@ThiagoHP: The first script is Ruby. The second script is Java.

@ddrum: Yes, we are adding an API for taking screenshots. We have approximately 20,000 visual tests where screenshot comparison is used, and we want to run these through the same framework as the rest.

Kevinexclipy Tuesday, March 10, 2009 10:35:50 AM

Nice one! Having Opera support in Webdriver will go a long way towards getting Opera supported better in Google web applications.

Shane Hayesshayes Tuesday, May 19, 2009 5:35:43 PM

So could you publish a timeframe? I would like to use BDD/FDD and something like Cucumber/Rspec to test. I'm not sure, but it seems your interface would be needed to do that. Am I right?
Shane

Daniel HendrycksDanielHendrycks Saturday, January 23, 2010 6:15:31 PM

Maybe we'll see it this following week smile

Johnhandsometechnews Thursday, April 22, 2010 9:43:52 PM

You are right Daniel but's it's 2 month now:D

oponto Tuesday, July 6, 2010 5:02:13 PM

looking forward to use Opera WebDriver (:

sirnh1 Wednesday, July 7, 2010 6:30:29 AM

488 days have past already. Any news on when we will be able to use something like this?

TangoDeltaDelta Tuesday, July 20, 2010 2:07:44 PM

Is there any way to join a developer group or anything to get access to the operawatir or webdriver code that supports testing in the Opera browser?

It's really needed badly for multi-browser, multi-platform web app testing . . . .

Daniel HendrycksDanielHendrycks Tuesday, July 20, 2010 2:51:24 PM

Originally posted by TangoDeltaDelta:

Is there any way to join a developer group or anything to get access to the operawatir or webdriver code that supports testing in the Opera browser?

It's really needed badly for multi-browser, multi-platform web app testing . . . .


They are on vacation, most of them at least. Hopefully, we will see it this fall.

Andreas Tolf Tolfsenandreastt Wednesday, August 4, 2010 7:19:46 PM

We _are_ working hard on this, and there will be a release in (hopefully) not too long. We've run into a lot of difficult issues underway, but we're at the same time making good progress.

Oh, and many of the requests above have already been implemented, but we're working hard on making it stable enough for a public release.

Daniel HendrycksDanielHendrycks Thursday, August 5, 2010 1:02:07 AM

Thanks for the update. bigsmile

TangoDeltaDelta Wednesday, September 1, 2010 3:05:17 PM

Originally posted by andreastt:

We _are_ working hard on this, and there will be a release in (hopefully) not too long. We've run into a lot of difficult issues underway, but we're at the same time making good progress.

Oh, and many of the requests above have already been implemented, but we're working hard on making it stable enough for a public release.



OK. Thanks! Still waiting for the ability to do automated testing in Watir or Selenium 2.x/WebDriver.

ANY way to get an approximate release date estimate?

yuuzhantar Wednesday, September 8, 2010 3:22:24 PM

Hi

No news about a release ? or a beta ?

TangoDeltaDelta Monday, November 8, 2010 3:53:47 PM

Well, it has been a couple of more months. Any updated estimate on an availability for a Watir or Selenium 2.x/WebDriver solution from the Opera team?

Daniel HendrycksDanielHendrycks Tuesday, November 9, 2010 2:17:44 AM

Maybe in Opera 11 beta!

Andreas Tolf Tolfsenandreastt Monday, December 6, 2010 4:40:43 PM

I wouldn't be surprised if Santa comes bearing gifts this Christmas. (-;

Daniel HendrycksDanielHendrycks Tuesday, December 7, 2010 1:10:07 AM

Originally posted by Andreas Tolf Tolfsen:

I wouldn't be surprised if Santa comes bearing gifts this Christmas. (-;


yes

Bruce Lawsonbrucelawson Tuesday, December 21, 2010 2:23:07 PM

DAVID HOLMBERGTRUEBUILT Friday, December 31, 2010 1:58:22 PM

USEING THIS ,IN THEROY ONE COULD SET UP UMBRELLA OR POD INDEPENDANT NETWORKS AIRTIOME OR WHATEVER PIGGIE BACKING AND JUMPING OTHER SIGNAL .THUS CREATING UR OWN INTR NET SERVICE????

TangoDeltaDelta Monday, January 3, 2011 7:15:15 PM

Originally posted by brucelawson:

Bruce Lawson 21. December 2010, 08:23

Awesome!! Let the site testing begin!

pseudo555 Wednesday, February 9, 2011 7:27:09 PM

Nice, but i think, i miss something.

OperaDriver driver = new OperaDriver();
throws the exception :
Exception in thread "main" org.openqa.selenium.WebDriverException: Launcher not available, please set it in path or use the JAR file

if i use :
OperaDriverSettings settings = new OperaDriverSettings();
settings.setOperaBinaryLocation("C:\\Program Files (x86)\\Opera");
settings.setOperaLauncherBinary("C:\\Program Files (x86)\\Opera\\opera.exe");
OperaDriver driver = new OperaDriver(settings);
Opera start, but nothings else append.

If i use :
OperaDriverSettings settings = new OperaDriverSettings();
settings.setOperaBinaryLocation("C:\\Program Files (x86)\\Opera");
settings.setRunOperaLauncherFromOperaDriver(true);
OperaDriver driver = new OperaDriver(settings);
I got :
Exception in thread "main" org.openqa.selenium.WebDriverException: Launcher not available, please set it in path or use the JAR file

What did i miss ?

Andreas Tolf Tolfsenandreastt Monday, March 28, 2011 10:02:25 PM

pseudo555: If you're using the OperaDriver jar, it will automatically extract a launcher to the home directory on your system (on Windows in C:\Documents and Settings\johndoe\.launcher\launcher.exe), and you should not have to set the setOperaLauncherBinary setting. It will also automatically guess the path to your Opera, so unless you've placed your Opera installation in a strange location it _should_ be able to find it.

The opera-launcher program is a C++ program we use to make sure screenshots are taken externally of Java, as Java had a tendency of triggering repaints which caused problems with some of our tests.

If you're including OperaDriver from source, you must explicitly set the path to the launcher binary as you've cleverly figured out how to do above. Note however that the launcher.exe and opera.exe are _not_ the same executables. OperaDriver launches the launcher, the launcher launches Opera.

Please let me know if you have any more problems!

set17 Sunday, April 10, 2011 10:47:03 AM

I have problem with Opera 11.01 starting.
Here waht I've done:
OS Win7 ULTIMATE SP1
1. Install JRuby 1.5.5 and Operawatir exactly as it discribed here http://www.opera.com/developer/tools/operawatir/install/
> No problem
2. Perform actions described here http://www.opera.com/developer/tools/operawatir/start/
- Setting up Opera
Once Opera is installed, some configuration is needed. Navigate to opera:config. Enable “Proxy Auto Connect”. Set “Home URL” to opera:debug and “Startup Type” to 2.
- On Windows 7, you can find these settings under “Control Panel” > “System and Security” > “System” > “Advanced system settings" > “Environment variables”.
Click the "New" button to add a new variable. Add the variable OPERA_PATH with the value C:\Program Files\Opera\opera.exe. If your Opera install is elsewhere, change the value accordingly.
Also, set the variable OPERA_LAUNCHER to C:\jruby-1.5.2\lib\ruby\gems\1.8\gems\operawatir-0.3-java\launchers\launcher-win32-i86pc.exe.
In my case I found launcher-win32-i86pc.exe here c:\Users\USER_NAME\.launcher\ so I put this in OPERA_LAUNCHER variable.
Both variables OPERA_LAUNCHER and OPERA_PATH created in User variables and System variables.
> No problem

And that's it. When I try to lounch this example.rb:
require 'rubygems'
require 'operawatir'
browser = Operawatir::Browser.new
browser.goto 'http://maps.google.com'
CMD hangs...

When I try it in jirb I got:
irb(main):001:0> require 'rubygems'
=> true
irb(main):002:0> require 'operawatir'
=> true
irb(main):003:0> browser = Operawatir::Browser.new
NameError: uninitialized constant Operawatir
from (irb):3

Thanks!

Write a comment

You must be logged in to write a comment. If you're not a registered member, please sign up.