Test automation with OperaWatir
By Wilhelm Joys Andersenwilhelmja. Friday, March 6, 2009 1:40:26 PM
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());
}
}

Tamil # Friday, March 6, 2009 2:43:13 PM
Tuttle # Friday, March 6, 2009 2:55:59 PM
I expect a release of this.
sirnh1 # Friday, March 6, 2009 3:01:06 PM
Aux # Friday, March 6, 2009 3:12:18 PM
dahulevogyre # Friday, March 6, 2009 3:43:52 PM
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
Charles SchlossChas4 # Friday, March 6, 2009 4:22:09 PM
Thiago H. de Paula FigueiredoThiagoHP # Friday, March 6, 2009 5:44:21 PM
dreamdrummerddrum # Friday, March 6, 2009 5:48:20 PM
Ravindran NavaneethanRavindran # Friday, March 6, 2009 6:14:07 PM
serious # Friday, March 6, 2009 8:30:22 PM
Michael Johnsonpitredbeard # Friday, March 6, 2009 9:30:14 PM
Martin RauscherHades32 # Saturday, March 7, 2009 12:55:55 PM
Barraco Mármol Jerónimojerobarraco # Sunday, March 8, 2009 4:05:49 AM
i'm proud of opera
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
Ice ArdorIceArdor # Monday, March 9, 2009 11:41:38 AM
Wilhelm Joys Andersenwilhelmja # Monday, March 9, 2009 11:49:43 AM
@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
Shane Hayesshayes # Tuesday, May 19, 2009 5:35:43 PM
Shane
Daniel HendrycksDanielHendrycks # Saturday, January 23, 2010 6:15:31 PM
Johnhandsometechnews # Thursday, April 22, 2010 9:43:52 PM
oponto # Tuesday, July 6, 2010 5:02:13 PM
sirnh1 # Wednesday, July 7, 2010 6:30:29 AM
TangoDeltaDelta # Tuesday, July 20, 2010 2:07:44 PM
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:
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
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
TangoDeltaDelta # Wednesday, September 1, 2010 3:05:17 PM
Originally posted by andreastt:
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
No news about a release ? or a beta ?
TangoDeltaDelta # Monday, November 8, 2010 3:53:47 PM
Daniel HendrycksDanielHendrycks # Tuesday, November 9, 2010 2:17:44 AM
Andreas Tolf Tolfsenandreastt # Monday, December 6, 2010 4:40:43 PM
Daniel HendrycksDanielHendrycks # Tuesday, December 7, 2010 1:10:07 AM
Originally posted by Andreas Tolf Tolfsen:
Bruce Lawsonbrucelawson # Tuesday, December 21, 2010 2:23:07 PM
DAVID HOLMBERGTRUEBUILT # Friday, December 31, 2010 1:58:22 PM
TangoDeltaDelta # Monday, January 3, 2011 7:15:15 PM
Originally posted by brucelawson:
Awesome!! Let the site testing begin!pseudo555 # Wednesday, February 9, 2011 7:27:09 PM
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
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
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!