Test automation

What is test automation? It is executing a test with preconditions, test steps and expected results without manual intervention or actions. In a typical case one would need to use several layers of tools for a fully functional test automation setup:

  • a test framework
  • a driver for controlling the browser
  • a system executing the tests, i.e. a continuous integration system

There are multiple tools available for each of the layers listed above and it's really up to user preference which one to use. The most popular open source tools for web test automation are Selenium and Watir. Selenium 2 is the new version, which provides a new and a more robust way of controlling the browsers.

Some time ago the people behind the Selenium and Watir frameworks decided that it is of no use to do duplicate work for the most time consuming part of the development, i.e. browser control and the teams decided to use a common framework for it. More information in watirmelon.

My favorite test framework is Cucumber and browser driver is watir-webdriver. Despite it's name, watir-webdriver is not the actual driver controlling the browser, but it uses selenium-webdriver underneath to manage different browsers. What it does is to provide is the excellent watir API on top of the selenium-webdriver to make the test automation work easier and the code more understandable.

I've used the selenium- and watir-webdrivers for about 2 years now in different type of test automation projects and it has been a joy to use.

watir-webdriver

Why watir-webdriver then? As mentioned above, it leverages the browser support from selenium-webdriver and provides the Watir API on top of it. There are some minor differences between Watir and watir-webdriver, but the differences are small and not of great importance especially if you're starting a new project.

Another advantage is using the ruby language for creating the test cases. Ruby is a language that's easier to get started with as a tester and provides the flexibility to create as complicated tests are required.

Examples

Here are some examples of using the API for some basic operations. The first example shows how to start a browser. The same operation is not repeated in the other examples, but it is assumed that a browser instance is available and assigned to variable browser.

Starting a browser (Firefox in this case)

require 'watir-webdriver'

browser = Watir::Browser.new :firefox

Navigating to a page

browser.goto "http://www.google.com"

Get the images on a page

browser.images

These are just some examples of the code and the readability that is one of the advantages of watir-webdriver. I will go into more details in future posts about this topic.