Skip to content

Introduction to Watir Robot

semperos edited this page Dec 28, 2010 · 4 revisions

The goal of this project, combined with Robot Framework, is to provide a tool which allows testers to build complex, automated test suites for functional web testing with a minimum of developer assistance. Watir Robot is a keyword library for Robot Framework which provides keywords relevant to functional web testing by leveraging the Watir-WebDriver project to drive a browser.

Watir, Robots, Testing, What?

Read the following sections to gather a better idea of each of this project's component parts.

Watir and Watir-WebDriver

Watir-WebDriver is the next generation of Watir, a Ruby library for performing browser-based automated web testing. Watir-WebDriver is a Ruby API atop the Ruby bindings for WebDriver, a library which provides mechanisms for driving Internet Explorer, Firefox, and Chrome, as well as a headless browser via Java's HtmlUnit. Watir-WebDriver has a number of advantages over standard Watir, which are discussed on the Watir Discussion page in this wiki.

Take a look at the following code to get an idea of how Watir-WebDriver works:

  require 'watir-webdriver'

  @browser = Watir::Browser.new :firefox

  @browser.goto "http://twitter.com"
  @browser.text_field(:id => 'username').set "my_username"
  @browser.text_field(:id => 'password').set "my_password"
  @browser.button(:value => 'Sign in').click

And you've logged into Twitter! There are many more facilities of interacting with HTML elements on the page, as well as browser cookies and history. See the Watir-WebDriver Basics page for more details.

Watir-WebDriver is solely concerned with driving a browser and as such is not a testing tool per se, unless you wrap it with testing code (RSpec, Cucumber, etc.). However, not all testers are developers; that's where Robot Framework comes in.

Robot Framework

Robot Framework is a keyword-driven, generic automated testing framework. Keywords are just simple English words or short phrases which can be used to write executable tests. The lowest-level keywords are implemented in actual code, but keywords can be combined to create new keywords inside test suites, providing the basis for advanced functionality and abstraction without writing any code.

As a generic automated testing framework, Robot Framework is quite suitable for web testing purposes, given a little help. The purpose of Watir Robot is to provide keywords specific to functional web testing, enhancing the core set of keywords provided by Robot Framework. Again, an example is in order (pulled from here: http://robotframework.googlecode.com/svn/trunk/doc/quickstart/quickstart.html#test-cases):

Test Case Action Argument Argument
User can create an account and log in Create Valid User fred P4ssw0rd
Attempt to Login with Credentials fred P4ssw0rd
Status Should Be Logged In
User cannot log in with bad password Create Valid User betty P4ssw0rd
Attempt to Login with Credentials betty wrong
Status Should Be Access Denied

Test cases like this are written in HTML, TSV, plain text or reStructuredText format, but there is a custom IDE called RIDE which allows you to write and organize your tests in spreadsheets and output them in whatever format you want.

Robot Framework's Remote Library Interface

If you just want to use Watir Robot, it's not necessary that you understand this section; just read the Usage > Practical Usage section of the README and start testing. For those who want a little more context, keep reading.

Robot Framework only supports keyword libraries implemented in Python and Java by default. In order to make our JRuby/Watir-WebDriver based keywords available to Robot Framework, we have to communicate with it via its Remote Library interface. This is accomplished by running a remote XML-RPC server written in our target language (JRuby) which "implements" the Remote Library interface via its callable functions.

A remote XML-RPC server has already been implemented in Ruby by the Robot Framework development team, and I've packaged it as the gem robot_remote_server on Rubygems.org. The robot_remote_server gem is defined as a dependency of this project, but if you've downloaded this code separately, make sure you install the gem separately.

To run your tests, you can run an instance of the remote server with Watir Robot's keywords by running the script scripts/run-server.rb. See the section on Extending Watir Robot for details on taking this setup further with your own low-level keywords.