Web Application Testing in
Ruby (WATIR)
Presented By
Unmesh Gundecha
Agenda
• Introduction to WATIR
• Pre-requisites for WATIR
• How WATIR works?
• Demo
• Why use WATIR?
• Limitations
• Other Tools
• More Info
• Q&A
VeriSoft InfoServices Pvt. Ltd
Introduction to WATIR
• WATIR (Web Application Testing in Ruby)
is an Open Source functional/regression
test automation tool for testing Web
Applications
• WATIR uses the Ruby programming
language to drive the Internet Explorer
web browser using IE’s Component Object
Model (COM) interface to access HTML
DOM
VeriSoft InfoServices Pvt. Ltd
Introduction to WATIR
• WATIR is not a record and playback tool.
It does not maintains any GUI Map or
Object Map.
• WATIR provides different ways to access
HTML objects
• WATIR development is led by Paul Rogers
and Bret Pettichord.
VeriSoft InfoServices Pvt. Ltd
WATIR in SDLC
The testing activities carried out by VeriSoft span the entire software development life-cycle.
WATIR
Works
Here
For each type of testing and testing activity, VeriSoft has a documented methodology based on theory and evolved over the
last 6 years and over 100 testing projects.
VeriSoft InfoServices Pvt. Ltd
Pre-requisites
Text Editor Ruby
(Notepad) Interpreter
(ruby182-14)
WATIR
Test Script
watirDemo.rb
WATIR Controller
(WATIR Tool Kit)
VeriSoft InfoServices Pvt. Ltd
How WATIR Works?
• WATIR creates a Instance of IE using the
WATIR IE Class. It then uses this instance
to access the HTML objects from the web
pages for verification
require ‘watir’
include Watir
$ie = IE.new
$ie.goto(http://www.google.com)
VeriSoft InfoServices Pvt. Ltd
How WATIR Works?
Accessing a HTML Element Button
In HTML:
<input type=submit value="Search" name=SearchButton>
In a Browser:
Now WATIR can access this button by
ie.button(:name,‘SearchButton’) or
ie.button(:type,‘submit’) or
ie.button(:index,1)
VeriSoft InfoServices Pvt. Ltd
What we can do with Button?
• Click It
ie.button(:value , ‘Search').click
• See if it exists
ie.button(:value , ‘Search').exists?
• Is it Enabled
ie.button(:value , ‘Search').enabled?
• Give it focus
ie.button(:value , ‘Search').focus
VeriSoft InfoServices Pvt. Ltd
Demo using irb (1)
• Type irb in Start->Run and click OK
• Create a instance of IE from WATIR
• Navigate to a web site
VeriSoft InfoServices Pvt. Ltd
Demo using irb (2)
• To See HTML of a page
• To see HTML objects from the page
VeriSoft InfoServices Pvt. Ltd
Demo using irb (3)
• To access a text field
– Flash
– Set
– Get Contents
– Verify Contents
VeriSoft InfoServices Pvt. Ltd
Demo using irb (4)
• To access a button
– Flash
– Click
• To check if pages contains some text
VeriSoft InfoServices Pvt. Ltd
Demo Application Test Plan
VeriSoft InfoServices Pvt. Ltd
Tips and Tricks
• Concurrent Execution
WATIR can run multiple instances of a single
test script with Ruby’s multithreading capabilities
• Using Regular Expressions
WATIR supports regular expressions in method
calls. Here is an example using the link method
to click a hyperlink using the url attribute:
ie.link(:url, /shtml/).click
This will click the link that matches shtml.
VeriSoft InfoServices Pvt. Ltd
Tips and Tricks
• Multiple Windows
WATIR handles multiple browser windows with
the attach method.
• File Upload
WATIR has a mechanism to support file
uploads. Use the file_field method. Run and
view the Ruby source in:"filefield_test.rb" in the
unittests folder for usage.
VeriSoft InfoServices Pvt. Ltd
Why Use WATIR?
• It’s Free
• It uses real programming language and
not a proprietary vendor script
• It’s Extensible, New Features can be
added easily
• Mailing list provide support
VeriSoft InfoServices Pvt. Ltd
Limitations
• Does not support ActiveX Plug-In
Applications, Java Plug-In Applications,
Flash Plug-In and other Plug-In
Applications
• Does not support browsers other than
Internet Explorer on Windows Platform
VeriSoft InfoServices Pvt. Ltd
Other Tools
• There are similar tools available Samie
(http://samie.sourceforge.net/) in Perl and
Pamie (http://pamie.sourceforge.net/) in
Python for Web Application testing using
IE Automation Object Model.
• Selenium with IE, Mozilla, Safari and
support for many languages: .net, ruby,
python, java
(http://selenium.thoughtworks.com/index.h
tml)
VeriSoft InfoServices Pvt. Ltd
More Info
• The WATIR home page
http://www.watir.com
• You can subscribe to wtr-general
(http://rubyforge.org/mailman/listinfo/wtr-
general) mailing list for latest information
on WATIR
• Get latest edition of Ruby from
http://rubyforge.org/projects/rubyinstaller/
VeriSoft InfoServices Pvt. Ltd
Questions and Answers
Contact Info
Unmesh Gundecha, SQA Analyst
VERISOFT InfoServices Pvt. Ltd.
3rd Floor, Sungrace Building, S.No. 19(6+7)/5, Bavdhan Khurd, Near Chandni Chowk, Pune
411 021 INDIA Tel. 91 20 22953931/32
www.verisoftindia.com
unmesh@verisoftindia.com
VeriSoft InfoServices Pvt. Ltd