RSS RSS feed | Atom Atom feed

My first experience with WATIR

I got an actual test plan for a new feature today - a list of manual test steps. I've been wanting to try out WATIR (Web Application Testing In Ruby) after learning about it from one of its creators, Bret Pettichord, who I had the pleasure of working with at DataCert. This seemed like the perfect chance to do something fun and useful. 

I started by getting confused. I googled "WATIR" and got a couple of links on the first page - one to wtr.rubyforge.org that looked promising, but also a link to openqa.org. After poking around a bit on both sites, I figured out that the current stable production version (and previous versions) are on rubyforge, but the team is moving things over to openqa.

I decided I wanted to start with the stable version of WATIR for now (1.4.1), so from the homepage at OpenQA, I first linked to the ruby installer - some difficulty there, as I got the most recent version (1.8.5-24), but later discovered that the 'modal dialog' functionality in Watir is only supported in an older version (1.8.2-15 is what I ended up installing). The next slightly confusing thing is that there are a couple of ways to install watir. There is an installer, or you can install it as a Ruby 'gem'. The main difference in 1.4.1 is that the installer creates some start menu shortcuts and includes some examples and unit tests. The gem install is pretty much just the core functionality. I went with the 1.4.1 installer at RubyForge.

After getting all that set up, I finally got to start playing with it. I started by just running the watir unit tests. I installed to c:\watir, so just doing start->run and typing in c:\Watir\unittests\all_tests.rb made it start going. When I first did this I discovered the issue with the modal dialogs - there is a test for that, and when it gets to that point a dialog pops up asking you to press OK. You can press OK manually, but after that the test just hangs and you have to use Process Explorer or Task Manager to kill the wayward ruby processes. There is also another issue with the 1.4.1 install - it doesn't copy some of the images used in the html of the tests, so there are some breakages there. I checked out the watir source from subversion (https://svn.openqa.org/svn/watir/trunk/) and then copied the images from there to my watir installation. Some of the docs at the new OpenQA site indicate that the dev team is working on the packaging in the 1.5 version.

Going back to Ruby 1.8.2-15 was supposed to have fixed the problem with the modal dialogs, but so far I haven't been able to get the unit tests to run all the way through. In any case, it is fun to watch them all run!

Next step was to go through the a tutorial I found at http://wtr.rubyforge.org/s101/doc/. I went through several steps, trying out watir interactively using irb. That is pretty cool. Definitely print out the Ruby Cheat Sheet and the Watir Cheat Sheet to help with that. While that is fun, and will probably be a powerful tool in the future, I wanted to be able to move a little faster. A bit more googling led me to some posts by Scott Hanselman about his 'WatirMaker', which has since evolved into a whole watir-recorder project at OpenQA. There are a couple versions of recorders there - WatirRecoirder C#, WatinRecorder C#, and a ruby version. Getting a pre-compiled binary wasn't working for me, so I just checked out the source and ran the ruby version. I wrapped it in a little batch file to redirect the output to a file, and made a small change to the recorder to have all the "puts" calls go through a new method 'record' that did a puts to both $stdout and $stderr so that I could redirect to a file AND see what it was doing. Hacky, I know.

You will probably also want to sign up for the wtr-general mailing list to get your questions answered.

So here is the step-by-step:

  1. Install Ruby 1.8.2-15 from RubyForge
  2. Install Watir 1.4.1 using the installer (Also on RubyForge)
  3. get the watir recorder from OpenQA
    http://svn.openqa.org/svn/watir-recorder/trunk
  4. Write and/or record tests!

So far, I am pretty excited about this. I've shown it to several people in my company, and that excitement is spreading. I even showed it to one of our internal users, and suggested that they might be able to use the recorder to document bugs - wouldn't that be cool? We still have a long way to go - coming up with a way to structure the tests, integrate them into our build system, and (if we record tests) refactoring the tests to start creating a library of common functions that could be re-used across tests - but it looks like a good start.

Here is the batch file I used to wrap WatirMaker.rb, which I got from https://svn.openqa.org/svn/watir-recorder/trunk/Ru...

@echo off
if .%1.==.. goto :GET_NAME
set TestName=%1
if exist %TestName% echo That test already exists & goto :EOF
goto :RECORD_TEST

:GET_NAME
set /p TestName=Please enter the name of the test:

:RECORD_TEST
title Recording %TestName%
ruby WatirMaker.rb > %TestName%

If you do a search/replace in WatirMaker.rb and replace "puts" with "record" and then add the method below, it will work for you like it did for me. Next thing is to have it take a command line argument that is the name of the file so that ruby itself can write to the file rather than using shell redirection.

##//////////////////////////////////////////
##
## send the output to stdout and to stderr,
## to allow the script to show the recording
## as it is happening as well as to a file.
##
##//////////////////////////////////////////
def record(message)
$stdout.puts message
$stderr.puts message
end



Re: My first experience with WATIR

Nice rundown.  You have a knack for getting things working.

Re: My first experience with WATIR

Testing comments on release 2.0.1

Add a comment Send a TrackBack