You are on page 1of 25

WATIR

Presented by Raquibul Bari raquibulbari@gmail.com

What is Watir?

Web Application Testing In Ruby


Pronounced like water Open-source Framework for browser-based automated testing. A browser driver. Can be used for testing web based applications.

Started as a library to teach testers to write ruby code.


Grew to be an IE implementation by Bret Pettichord.

Now supports IE, Firefox, Safari, Google Chrome and Opera. As well headless browser support using HtmlUnit through Celerity and Schnell.

What is Watir? (Contd.)

Test scripts written in the Ruby programming language.


Simulate the user actions (filling/submitting forms)

Various assertions (content-based)


Connects to databases Reading data files Exporting data (xml/html/excel) Current release is 4.0.0. Can be found in http://watir.com/installation/

Is not?
Watir is not a record/playback tool. However, there are several recorders out there WatirMaker Watir WebRecorder Webmetrics RIA Script Recorder Watir is not a link checker However, you can easily write your own link

checker and customize it to your specific needs. Watir is not a test case management tool. However, you can write one in Ruby if desired. Doesnt test Flash or Applets or Microsoft Silverlight.

What you do without automation?


Navigate the browser Find elements on the page Interact with elements on the page Check output on the page Create and use Methods Create formal test cases Get the report file

Why use WATIR?


No need to be a professional developer to write watir scripts. Yet you are learning a robust programming language. Ideal for functional or integration level testing. Full power of Ruby available in test scripts. Find bugs that unit tests miss.

Automates what is usually a manual tedious process.

Watir Architecture

IE COM

FF JSSH

Apple Events

V8 Debugger

Dragonfly

WATIR API

Component 1

Component 2

Component 3

Component 4

Test Script

Your awesome framework

Ruby advantage

Since WATIR is ruby based web application testing framework, we can customize the script according to our needs. Taking Rubys Object Oriented concepts, create more dynamic/customized scripts Use classes & methods effectively Access even the database to validate the data

Watir is cool because


It is written in Ruby and open source. It has standardized interface across browsers. The API and implementation is clean, intuitive and simple. Supports major browsers. And fast headless browser support through Celerity and Schnell. Good locator support Easily extensible. Active community (Watir wiki, mailing list and irc). Agile principles like refactoring, continuous integration and short releases strictly followed. Has corporate support (www.watircraft.com).

Watir can be better because


Watir with WebDriver is a powerful tool which can Handle inner frames With webdriver browser certificate or authentication management Can manage cookies Can handle javascript dialogs Measure page performance Take Screenshots Send special input characters WYSIWYG Editor handling And many more....

Frameworks using Watir


Frameworks built using Watir as core RSpec Behavior driven development Cucumber - a FIT influenced keyword driven framework Test/Unit Basic Unit testing framework. Watirloo - Semantic Page Objects Modelling WatirGrid Distributed watir Excel and Wiki driven frameworks More frameworks are out there
For more info on frameworks, please see Watir wiki.

Let's get started!!

Install on Mac
As Watir is cross platform, it can be installed in Windows/Mac/Linus. We are showing mac steps here 1. Install Ruby 1.8.7 2. Install RubyGems 3. Install OSX GCC or Xcode 4. Install Safari Watir 1) go to command window 2) sudo gem install safariwatir no-ri no-rdrc

5. Install watir-webdriver
6. For FireFox, Chrome and Opera some custome component needs to be installed.

Using Watir

Using watir is very easy

Reference the Watir using the require keyword and start coding

require "watir-webdriver" browser = Watir::Browser.new :chrome browser.goto "http://bit.ly/watir-example" browser.text_field(:name => 'entry.0.single').set 'Watir' browser.close

How do I identify objects?

Use View Source Firebug in firefox, or IE toolbar or inspect element in chrome. USE IRB

Manipulating web browser objects


Button manipulation b = browser.button(:value, "Click Here") b.click CheckBox c = browser.checkbox(:name, "enabled") c.set Link l = browser.link(:url, "http://google.com") Forms f = browser.form(:action, "submit") f.submit Table browser.table(:id, 'recent_records').to_a And many more...

Closer view

browser.button(:value, "Click Me").click

[Variable] . [method] (: [element] , [unique identifier] . [method]

Qvantel Oy 2006. www.qvantel.com

WATIR Examples
ie.link(:id, lnk1).click ie.button(:id, btn1).click ie.link(:name, lnk1).exists? ie.contains_text(Welcome) wait_until {@browser.contains_text Edit"}

WATIR can find elements by id, name, text, link, XPath, etc WATIR uses the OLE/COM automation interface to control the browser.

Sample Watir Test Script


require 'watir-webdriver' require 'test/unit' class TC_article_example < Test::Unit::TestCase

def test_search browser = Watir::Browser.new browser.goto("http://www.google.com/ncr") browser.text_field(:name, "q").set("pickaxe") browser.button(:value, "Google Search").click assert(browser.text.include?("Programming Ruby: The Pragmatic Programmer's Guide")) end
end

WATIR Alternatives
WatiN.(.NET Framework
Watij (Java) Win-32-Watir, Perl Gambit Commercial Products Compuware TestPartner Usually based on record-playback techniques Selenium Similar open source browser automation framework.

Scripts are written in custom macro language.

What Next?

Watir+Selenium+WebDriver
Watir with a regression server for continuous regression testing Organizations planning to use automated testing are adopting watir. Watir is a keypart of facebook engineering. They customized it for own purpose. WebDriver with watir

Cucumber and Watir-WebDriver is a match made in heaven.


Mobile site testing. WatirGrid: Distributed and co-ordinated watir Adding intelligence in watir

References
Watir Wikipedia: http://en.wikipedia.org/wiki/Watir

Watir main site: http://wiki.openqa.org/display/WTR/


Watir element:http://wiki.openqa.org/display/WTR/HTML+Elements+Supported+by+Watir Watir user guide: wtr.rubyforge.org/watir_user_guide.html Watir API: wtr.rubyforge.org/rdoc/index.html User Contributions/examples: http://wiki.openqa.org/display/WTR/Contributions Watir FAQ: http://wiki.openqa.org/display/WTR/FAQ OperaWatir: http://people.opera.com/andreastt/2011/04/watir-future/ WatirGrid: http://wiki.openqa.org/display/WTR/WatirGrid Watir Cheat Sheet: http://wiki.openqa.org/display/WTR/Cheat+Sheet WatirMelon: http://watirmelon.com/ Intro to Watir: http://www.scribd.com/doc/60527257/Introduction-to-Watir Ruby Ruby site: http://ruby-lang.org Ruby Quickstart: ruby-lang.org/en/documentation/quickstart/

Questions?

Thank You!!

You might also like