Automated Testing With Watir

Preview:

DESCRIPTION

An overview of using the Watir testing framework to create a testing DSL for browser-based integration testing.

Citation preview

Automated Testing with Automated Testing with WATIRWATIR

Timothy Fisher

What is WATIR?What is WATIR?

Web Application Testing In Ruby Open-source Framework for browser-

based automated testing.Test scripts written in the Ruby

programming language.Natively supports IEExtensions support Firefox and SafariPronounced like “water”

Why use WATIR?Why use WATIR?

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.

More to come…

WATIR Testimonials

• A few testimonials from WATIR website:– watir rules. It easily outperformed every other automation tool we

evaluated…

– the most useful piece of software I’ve ever evaluated…

– watir is by far the most complete web testing framework out there…

– Watir is the most compelling alternative for filling the automated acceptance test need. (Ward Cunningham)

– With watir, we are able to test with ease and ship with confidence.

• And last but not least:– watir blew my freakin mind. Everything worked, no fuss, no muss, no

bother.

– I’m so happy to discover Ruby and Watir. I wanted to run around my office dancing and celebrating.

WATIR Examples

ie.link(:id, “lnk1”).clickie.button(:id, “btn1”).clickie.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.

Creating a Test DSL with WATIRCreating a Test DSL with WATIR

What is a DSL? Domain Specific Language a language designed for a specific domain

Testing DSL A language design specifically for browser-

based testing.

Test FrameworkTest Framework

Test ScriptsTest Scripts

App Specific Test DSLApp Specific Test DSL

WATIR Test FrameworkWATIR Test Framework

Ruby run-timeRuby run-time

Test Script ExampleTest Script Example

launch_myapp ENVIRONMENT, :port=>PORT

login_as USERNAME, PASSWORD

goto_page :configuration

select_tab :partners

add_new_partner :label=>'TestPartner'

save_configuration

Test Scripts

DSL ExampleDSL Example

def login_as(user, password) # enter user name and password

@browser.text_field(:name, 'member_name').set(user)@browser.text_field(:name,'member_password').set(password)

# submit login form@browser.form(:id, 'formLogin').submit

@browser.wait # verify you have reached the welcome page

assert @browser.contains_text("Catalog Data Quick Overview")puts "Successfully logged in."

end

Test ScriptsApp Specific Test DSL

ObservationsObservations

Test scripts use very simple application targeted language.

Only DSL implementation uses WATIR API

With training QA could write test scripts.

Test Scripts Everywhere…

Test scripts can be written before development. practice test-driven development. embed in Use Cases to achieve testable use

cases, executable specifications.

Defects can be described using a Test Script that reproduces the defect. attach script to bugzilla defect.

Recording ScriptsRecording Scripts

Watir Recorder++

Firewatir RecorderRecords user action while user is interacting

with the applicationUser TestGen4Web XPI for capturing user

actionsConvert user actions to XMLConvert XML to ruby file for playback using

tg4rb gem

WATIR AlternativesWATIR Alternatives

Selenium Similar open source browser automation

framework. Scripts are written in custom macro language.

Commercial Products Compuware TestPartner Usually based on record-playback techniques

ReferencesReferences

• Watirhttp://wtr.rubyforge.org

• Firewatir http://code.google.com/p/firewatir

• tg4rb http://code.google.com/p/tg4rb

• TestGen4Webhttp://developer.spikesource.com/wiki/index.php/Projects:TestGen4Web

• Seleniumhttp://www.openqa.org/selenium/

• Compuware TestPartnerhttp://www.compuware.com/products/qacenter/375_ENG_HTML.htm

Recommended