Tuesday, January 17, 2012


I know I'm late to this, but I'll share anyway:

If you're actively developing or supporting anything with a web front end, take a look at watir for automated smoke and regression tests. The site has a "watir in 5 minutes" page, but probably really takes more like 3, it's that well designed.

Watir stands for:Web Application Testing in Ruby. It is:
  • Open source
  • Simple to install: just a ruby library (gem)
  • All of ruby is available when writing test scripts
  • Well regarded
  • Widely used. Here's a partial list:

Some Watir Users

Watir Limitations

  • “W3C” web only!
    • No plug-ins (active-x, flash)
  • No recording
      Recording tools are available, but not part of the core effort
Watir Advantages
  • Widely used
  • Very easy to use
  • Programmer friendly
  • Ruby is sane
  • Terse without being obtuse
Interactive Development
    You can debug scripts interactively using irb

For example, this screenshot shows a section of a browser wind and an irb window about to execute a method to click on the browser's edit button:

Screen Shot 2012 01 16 at 1 30 17 PM

resulting in:

Screen Shot 2012 01 16 at 1 30 43 PM
Page elements are referenced by
  • Type and Id/displayed-text/link destination etc
    • @browser.select_list(:id, 'StatusSelect')
  • or Index
    • @browser.buttons[3]
        Index is obviously not the preferred approach, but it is occasionally necessary, e.g., for pages with four identical “submit” buttons

On a maintainability note: I recently had to change a script from FireFox (which I'm increasingly becoming disenchanted with) to Chrome. The change only required altering 2 lines of code

#require 'firewatir'

require "watir-webdriver"


#    @browser = Watir::Browser.new

@browser = Watir::Browser.new(:chrome)

However, I did find the behavior a bit different between Chrome and Firefox: If a button wasn't visible on the page Chrome wouldn't click it. I never had a issue with this in Firefox.

Update:, upon further investigation it appears that may be the behavior of the newer versions of watir, rather than a Chrome compatibility issue.

No comments: