14
Automated Testing with Automated Testing with WATIR WATIR Timothy Fisher

Automated Testing With Watir

Embed Size (px)

DESCRIPTION

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

Citation preview

Page 1: Automated Testing With Watir

Automated Testing with Automated Testing with WATIRWATIR

Timothy Fisher

Page 2: Automated Testing With Watir

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”

Page 3: Automated Testing With Watir

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…

Page 4: Automated Testing With Watir

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.

Page 5: Automated Testing With Watir

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.

Page 6: Automated Testing With Watir

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.

Page 7: Automated Testing With Watir

Test FrameworkTest Framework

Test ScriptsTest Scripts

App Specific Test DSLApp Specific Test DSL

WATIR Test FrameworkWATIR Test Framework

Ruby run-timeRuby run-time

Page 8: Automated Testing With Watir

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

Page 9: Automated Testing With Watir

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 [email protected](: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

Page 10: Automated Testing With Watir

ObservationsObservations

Test scripts use very simple application targeted language.

Only DSL implementation uses WATIR API

With training QA could write test scripts.

Page 11: Automated Testing With Watir

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.

Page 12: Automated Testing With Watir

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

Page 13: Automated Testing With Watir

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

Page 14: Automated Testing With Watir

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