Automated Testing with WATIR Timothy Fisher
What is WATIR? W eb  A pplication  T esting  I n  R uby  Open-source Framework for browser-based automated testing. Test scripts written in the Ruby programming language. Natively supports IE Extensions support Firefox and Safari Pronounced like “water”
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”).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.
Creating 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 Framework Test Scripts App Specific Test DSL WATIR Test Framework Ruby run-time
Test 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 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 Scripts App Specific Test DSL
Observations 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 Scripts Watir Recorder++ Firewatir Recorder Records user action while user is interacting with the application User TestGen4Web XPI for capturing user actions Convert user actions to XML Convert XML to ruby file for playback using tg4rb gem
WATIR 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
References Watir http://wtr.rubyforge.org   Firewatir  http://code.google.com/p/firewatir tg4rb  http://code.google.com/p/tg4rb TestGen4Web http://developer.spikesource.com/wiki/index.php/Projects:TestGen4Web Selenium http://www.openqa.org/selenium/   Compuware TestPartner http://www.compuware.com/products/qacenter/375_ENG_HTML.htm

Automated Testing With Watir

  • 1.
    Automated Testing withWATIR Timothy Fisher
  • 2.
    What is WATIR?W eb A pplication T esting I n R uby Open-source Framework for browser-based automated testing. Test scripts written in the Ruby programming language. Natively supports IE Extensions support Firefox and Safari Pronounced like “water”
  • 3.
    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…
  • 4.
    WATIR Testimonials Afew 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.
  • 5.
    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.
  • 6.
    Creating a TestDSL 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.
  • 7.
    Test Framework TestScripts App Specific Test DSL WATIR Test Framework Ruby run-time
  • 8.
    Test Script Examplelaunch_myapp ENVIRONMENT, :port=>PORT login_as USERNAME, PASSWORD goto_page :configuration select_tab :partners add_new_partner :label=>'TestPartner' save_configuration Test Scripts
  • 9.
    DSL Example deflogin_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 Scripts App Specific Test DSL
  • 10.
    Observations Test scriptsuse very simple application targeted language. Only DSL implementation uses WATIR API With training QA could write test scripts.
  • 11.
    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.
  • 12.
    Recording Scripts WatirRecorder++ Firewatir Recorder Records user action while user is interacting with the application User TestGen4Web XPI for capturing user actions Convert user actions to XML Convert XML to ruby file for playback using tg4rb gem
  • 13.
    WATIR Alternatives SeleniumSimilar open source browser automation framework. Scripts are written in custom macro language. Commercial Products Compuware TestPartner Usually based on record-playback techniques
  • 14.
    References Watir http://wtr.rubyforge.org Firewatir http://code.google.com/p/firewatir tg4rb http://code.google.com/p/tg4rb TestGen4Web http://developer.spikesource.com/wiki/index.php/Projects:TestGen4Web Selenium http://www.openqa.org/selenium/ Compuware TestPartner http://www.compuware.com/products/qacenter/375_ENG_HTML.htm