A blog about software development and other software related matters

Blog Archive

Tuesday, April 17, 2007

A glass of Watir to quench your thirst

A couple of years ago (long before rails was in focus) Ruby has caught my eyes , to be exact it was Watir which is a Ruby based web testing framework that took my attention , at the time i didnt know how much useful it can be.
Watir is quite interesting since it drives the actual web browser UI (IE) during testing procedures , this makes it extremely simple to use , you don't have to sniff any http posts or use low level API , just select your DOM element and the operation that you wish the browser to perform on it:

ie = IE.new # our IE window
ie.text_field(:name, "typeinme").clear # clearing out a text field that carries the name typeinme

What can you do with it?
Well There are many applications (besides basic testing) that can utilize it such as:
• Web site monitors that scans web sites at certain intervals and look for errors.
• Web crawlers and Form data extractors.
• Applications that automatically recreate bugs (using saved user input data).

The fact that Watir is Ruby based makes its very extensible , you can use it in conjunction with Rails to create a web based management console for your application , fetching of input data can be done easily with ActiveRecord from you favorite DB.

Watir has its downsides too , its not very efficient since it requires an entire machine (as long your program keeps on running) , also since it works at the UI level (IE is its main resource) it takes a large amount of computing power (especially when there are a couple of them open).
Watir largest drawback is that its only supports IE at the current moment (support for Mozilla is planned on the next release) which is quite limiting (at least you can use this hack for running it on Linux) , still trust me Watir is one of the most useful frameworks youl ever stumble upon.


Bret said...

Actually, if you run your scripts with the "-b" flag, they will not take over your desktop.

ronen said...

Hey Bret , sorry for the late reply
Iv tried to start the script with:
ruby -b MyScript.rb
But there dosnt seem to be such a flag for the interpreter , where did i go wrong ? :)

BTW i gave the following lines also a go:

$HIDE_IE = true;
ie = Watir::IE.new()

but it didn't do the trick

Thanx for your advice!