Popular Posts

Thursday, July 31, 2008

Web application testing in Ruby(Watir) - 2 minutes guide

Watir (pronounced as Water) is a free open source tool which can be used to automate web applications. It is an extension of Ruby programming language. Unlike most of the other testing tools it gains the advantage of powerful features of Ruby and simulate browser interactions in very simple manner.
Lets see how a simple google search is automated using Watir in few steps.

Install Ruby (1.8.5-24 or later)

Step 1

Install Watir. Open a command window or shell and issue the following commands
gem update --system
gem install watir

The above two commands update gem installer and then install watir in your system.

Step 2

Open SciTE ruby editor or notepad and start to create the following script.

require "watir"

ie = Watir::IE.new


ie.text_field(:name, "q").set("WSO2 WSAS")

ie.button(:name, "btnG").click

Step 3

Save the above file as SimpleTest.rb and run it from the command line by typing SimpleTest.rb
You will see that an Internet Explorer browser instance will automatically be popped up, access google, type "WSO2 WSAS" text and click on search button as a user interacts with the web site.

Step 4

Lets see what each of the above statements of our test script do.

require "watir" - This is similar to an import statement. This tells ruby script to use Watir as an extension library

ie = Watir::IE.new - Instantiate a new IE browser instance and open it

ie.goto("http://www.google.com") - Instructs IE instance to access google.com

ie.text_field(:name, "q").set("WSO2 WSAS") - Set text, "WSO2 WSAS" as the search query

ie.button(:name, "btnG").click - Click the "search" button

If you need to simulate web interaction with Firefox, you can use FireWatir, which allows to write test scripts for Firefox browser.


Unknown said...

Hi, I have to test a Ruby application and Eclipse is the IDE I am using. So what are the steps required to do the testing on Eclipse?

Charitha said...

Please read http://wiki.openqa.org/display/WTR/Setting+up+Eclipse+for+Ruby


Unknown said...

Thanks, can you suggest me that I have to do the testing of a migration utility from a file to MySQL database on the Rails platform. I am using Ruby to code the utility. So is Watir is a good tool to do such testing and how can I measure the performance of those utilites e.g time taken from starting to finishing etc..etc
I will be really thankful to you for this guidance.

Charitha said...

Though I haven't got any experience with Rails, Watir is a tool for web application testing. As its name implied, Watir is a tool to test web apps using Ruby. Your scenario does not seem to have typical web interactions. Therefore, I think you may use a tool like Apache Jmeter.

Rajasekaran said...

I have some doubt in script of Text field...

http://www.google.com/analytics/ -> Click on Access Analytics -> Unable to enter data in Email and Password field using IRB command window....

I entered command as
ie.text_field(:name, "Email").set "raja"
ie.text_field(:name, "passwrd").set "raja"

Kindly help me to write the script for above senerio......

Eric Fried said...


I have been using Ruby/WATIR to automate our application here, but I have run into a roadblock.

On one of the views in our web app, they have implemented an SVG object, representing a clickable grid of data. WATIR cannot read the data or the cells within this object. Is there some way I can read it?

Unknown said...

Hi Charitha,

I am new Watir. I have following all the steps. I am tring to execute your example. I am not able to start new IE instance. Can you please help me here.

C:\Ruby>"C:\Documents and Settings\spanchumarthy\Desktop\Project_info\Watir\Simp
C:/Ruby/lib/ruby/gems/1.8/gems/windows-pr-0.9.3/lib/windows/thread.rb:59: uninit
ialized constant Windows::API::Error (NameError)
from C:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `ge
from C:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `re
from C:/Ruby/lib/ruby/gems/1.8/gems/win32-process-0.5.9/lib/win32/proces
from C:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `ge
from C:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `re
from C:/Ruby/lib/ruby/gems/1.8/gems/watir-1.6.2/lib/watir/ie-process.rb:
from C:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `ge
from C:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `re
from C:/Ruby/lib/ruby/gems/1.8/gems/watir-1.6.2/lib/watir/ie.rb:45
from C:/Documents and Settings/spanchumarthy/Desktop/Project_info/Watir/

Anonymous said...

Thank you so much!!polo shirt men'ssweate,Burberry Polo Shirts lacoste sweater, ralph lauren Columbia Jackets,ski clothing. Free Shipping, PayPal Payment. Enjoy your shopping experience on mensclothingus.com.You can find the father who desire fashionable, intellectual mens clothing simultaneously.

Anonymous said...

God bless you!I really agree with your opinions.Also,there are some new fashion things here,gillette razor blades.gillette mach3 razor bladesfor men.As for ladies,gillette venus razor blades must the best gift for you in summer,gillette fusion blades are all the best choice for you.

Anonymous said...

Perfect!!You are a outstanding person!Have you ever wore chaussures puma,Here are the most popular puma CAT,Puma shoes store gives some preview of puma speed cat,and casual but no sweat puma basket.

Anonymous said...

Do not mean bad.Thank you so much!I just want to show some fashion things to all of you.I like puma speed, puma femmes and other puma shoes. These puma sport items are at store recently and available for anyone.

Anonymous said...

Fantastic!God bless you!Meanwhile,you can visit my China Wholesale,we have the highest quality but the lowest price fashion products wholesale from China.Here are the most popular China Wholesale productsfor all of you.You can visit http://chinaclothes.net.Also the polo clothing is a great choice for you.

Anonymous said...

The larger that the head size is for your babolat pure drive, the more power you will be provided with. Additionally, a larger wilson k six size means a larger sweet spot which is why beginners as well as intermediate players often prefer to work with a head microgel with a larger head size. Additionally, thicker frames are also capable of generating more power as well. Smaller head sizes on prince-o3-tour on the other hand are capable of providing less power, but significantly more control cheap tennis racquets.new polos men poloswomen polosdiscount polossummer polospolo shirts whosalepolo fashionembroodered polostennis racketsclothing poloclothingedhardyshirtedhardyclothingsummer ed hardy clothingcheap shirtsed hardy brand.

Anonymous said...

Although many people criticize ed hardy clothing for having nothing but tattoo patterns, being filled with waste and useless things, it is widely acknowledged that ed hardy clothes draws the most attention of both common young people as well as many Hollywood welcomed stars for its punk ed hardy t-shirts rock styles. As a matter of fact, in such a world where all ed hardy shirts are much like each other, ed hardy mens creates yet another totally new global sensation in fashion crowd for ed hardy womens fancy design. An increasing number of people are charmed by the magic of amazing tattoo and impressive color of ed hardy sunglasses.

Anonymous said...

In this version of the ralph lauren polo, the styling and fabric is advertised as being made out of "playdry" material. Burberry Polo Shirts is another performance fabric which is intended to add luxury Cheap polo shirts, coolness, and moisture wicking qualities. Performance fabrics wholesale polo shirtswere originally created primarily for athletes and other sports enthusiasts who work up a good sweat ralph lauren polo shirts. The moisture wicking fabric in cheap ralph lauren polos draws the moisture away from the body which then evaporates quickly discount ralph lauren polos. ralphlaurenpoloshirts keep the body cooler and drier even when the athlete is under physical duress polo clothing.

Anonymous said...

polo ralph lauren RED! Series of design criteria - stylish, simple, self-cultivation. For the first time in 2009 in New York Fashion Week debut, RED! Series has a new Polo Shirts On Sale series from the traditional burberry polos LOGO, LOGO traditional crocodile logo at the Ralph Lauren Polo Shirts letter above, and the new series of letters with the cheappolos logo in line to be between a red symbol of Burberry Polo Shirts.

Anonymous said...


Anonymous said...

There are ed hardy shirts
,pretty ed hardy shirt for men,

ed hardy womens in the ed hardy online store

designed by ed hardy ,
many cheap ed hardy shirt ,glasses,caps,trouers ed hardy shirts on sale ,

You can go to edhardyshirts.com to have a look ,you may find one of ed hardy clothing fit for you
Top qualitymen's jacket,
These cheap jacket are on sale now,you can find
north face jackets inmage on our web
Ralph Lauren Polo Shirtsbuberry polo shirts

Do you wannaghd hair straighteners for you own , we have many
cheap ghd hair straightenersin style and great,you can choose one from these
hair straighteners
Authentic chaussure puma
chaussure sport
And chaussure nike shoes

Anonymous said...

Come here to have a look of our Wholesale Jeans
Many fashionMens Jeans ,eye-catching
Womens Jeans ,and special out standing
Blue Jeans ,you can spend less money on our
Discount Jeans but gain really fine jeans, absolutely a great bargain.
China Wholesale
wholesale from china
buy products wholesale
China Wholesalers