Monday, August 27, 2012

Watir & Watir-webdriver

Watir is an open-source tool for automating web browsers. Watir supports only IE, but Watir-webdriver supports also Firefox, Chrome and Safari. Scripting language is Ruby.

Watir is a bit more mature, faster and stable than watir-webdriver. Watir is also always automatically waiting for the pages / components to fully load before continuing, not like Selenium or Watir-webdriver where you sometimes have to add extra code for that.

If you don't care about running scripts in different browsers or on different operating systems, then I would use Watir. If you want to run your scripts against different browsers or your application is having frames / iframes, then I would use Watir-webdriver.

Ruby is an excellent scripting language with a lot of existing gems for e.g. ssh, ftp, http and mysql connectivity. Watir doesn't have any in-built logging functionality, but using it together with Cucumber makes it an excellent tool / framework for testing web applications.

Watir is a tool developed by testers for testers.


Installation

 

  1. Download Ruby installer from http://www.rubyinstaller.org and run it. During installation select Ruby to be added to PATH and to associate .rb files to this Ruby installation.
  2. Download Ruby Devkit from http://www.rubyinstaller.org and extract it. In the extracted folder, run commands ruby dk.rb init and ruby dk.rb install to setup and install it.
  3. Install Watir gem with command: gem install watir
  4. Install Watir-webdriver gem with command: gem install watir-webdriver
 
Example script - Google search

 

require 'rubygems'
require 'watir-webdriver'

begin   
    browser = Watir::Browser.new(:firefox)
   
    puts "Go to google.com"
    browser.goto "http://www.google.com"

    puts "Search for Watir"
    browser.text_field(:name, "q").set "Watir"
    browser.button(:id, "gbqfb").click
   
    Watir::Wait.until { browser.text.include? 'Web Application Testing in Ruby' }
   
    browser.close

rescue
    puts "FAILED: " + $!.to_s
    browser.close
end

 
More information

 


 

No comments:

Post a Comment