Skip navigation.

Log in | Sign up

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 6. March 2009, 14:43

:up:

Tuttle 6. March 2009, 14:55

Nice feature.
I expect a release of this. :D

sirnh1 6. March 2009, 15:01

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

Aux 6. March 2009, 15:12

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

dahulevogyre 6. March 2009, 15:43

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

Fantastic !

FataL 6. March 2009, 15:45

I hope this will help you fight regressions. :wait:

Chas4 6. March 2009, 16:22

:up:

ThiagoHP 6. March 2009, 17:44

In what language is that script written?

ddrum 6. March 2009, 17:48

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 6. March 2009, 18:14

Great !!!

serious 6. March 2009, 20:30

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

pitredbeard 6. March 2009, 21:30

@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.

Hades32 7. March 2009, 12:55

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

jerobarraco 8. March 2009, 04:05

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 9. March 2009, 09:40

This looks really cool.

IceArdor 9. March 2009, 11:41

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.

wilhelmja 9. March 2009, 11:49

@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.

exclipy 10. March 2009, 10:35

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

shayes 19. May 2009, 17:35

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

Write a comment

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