INTRODUCTION

‘Watir’ (pronounced water) stands for ‘Web Application Testing in Ruby’ is a very powerful tool. It is an open-source (BSD) family of Ruby libraries for automating web browsers. It allows you to write tests that are easy to read and maintain. Watir is an automated test tool which uses the Ruby scripting language to drive the Internet Explorer web browser. Watir is a toolkit for automated tests to be developed and run against a web browser.

Watir drives browsers the same way people do. It clicks links, fills in forms, and presses buttons. Watir also checks results, such as whether expected text appears on the page.

Watir is a family of Ruby libraries but it supports your app no matter what technology it is developed in. Whilst Watir supports only Internet Explorer on Windows, Watir-WebDriver supports Chrome, Firefox, Internet Explorer, Opera and also running in headless mode (HTMLUnit).

INSTALLATION

Installing the Software – In order to use Watir you will first need to install Ruby: using the windows installer and then install Watir itself.

Ruby Installation

Open a command prompt (Run and type cmd) and type ruby -v to see if you have Ruby installed (if you don’t it will say the command isn’t recognized) and the version number.

Use the 32 bit installers from RubyInstaller Downloads including:

Ruby 2.0.0-p247

DevKit-mingw64-32-4.7.2

Run the Ruby installer and on the optional tasks page select the below items before completing:

Add Ruby executables to your PATH

Associate .rb and .rbw files with this Ruby installation

Open a new command prompt and type ruby -v to see if Ruby installed and the version number.

(Optional) Once installed you can update the RubyGems distributed with the installer by typing gem update –system and watching for the “RubyGems system software updated” to know when it’s complete.

Move on to the DevKit installation.

DevKit Installation

Run the DevKit installer but change the extraction folder to C:\devkit

Open a command prompt (Run and type cmd) and change the folder to C:\devkit (use the command cd c:\devkit).

Run the command ruby dk.rb init. If this step is successful you’ll see a response like “[INFO] found RubyInstaller v2.0.0 at C:/Ruby200”.

Run the command ruby dk.rb install. If this step is successful you’ll see a response like “[INFO] Installing ‘C:/Ruby200/lib/ruby/site_ruby/2.0.0/rubygems/defaults/operating_system.rb'” and “[INFO] Installing ‘C:/Ruby200/lib/ruby/site_ruby/devkit.rb'”

Move on to Watir installation.
Watir Installation

Problems occur with the 2.0.0 version of Watir. Something about the mini_magick version erroring out. To prevent this problem we do:

Run the command (still from the C:\devkit command window) gem install mini_magick -v 3.5.0 which works around the version problem. You should get a response like “2 gems installed”

Then run the command gem install watir –no-ri –no-rdoc to install the rest of Watir. You should get a response like “Successfully installed watir-4.0.2-x86-mingw32 and 23 gems installed”.

Check the Installation

In the same command window type (after each line of code submit the commands)

irb

require “watir”

browser = Watir::Browser.new

browser.goto “google.com”

If all is setup correctly you should get your default browser to open a new window and then browse to Google.
Script a simple Google search with WATIR using Elipse as the IDE

require “watir”

url = “www.google.com

ie = Watir::IE.new

ie.goto url

ie.text_field(:name, “q”).set “showmedo.com”

ie.button(:name, “btnG”).click