Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Automated Testing With Watir

18,231 views

Published on

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

Published in: Technology
  • Be the first to comment

Automated Testing With Watir

  1. 1. Automated Testing with WATIR Timothy Fisher
  2. 2. What is WATIR? <ul><li>W eb A pplication T esting I n R uby </li></ul><ul><li>Open-source Framework for browser-based automated testing. </li></ul><ul><li>Test scripts written in the Ruby programming language. </li></ul><ul><li>Natively supports IE </li></ul><ul><li>Extensions support Firefox and Safari </li></ul><ul><li>Pronounced like “water” </li></ul>
  3. 3. Why use WATIR? <ul><li>Ideal for functional or integration level testing. </li></ul><ul><li>Full power of Ruby available in test scripts. </li></ul><ul><li>Find bugs that unit tests miss. </li></ul><ul><li>Automates what is usually a manual tedious process. </li></ul><ul><li>More to come… </li></ul>
  4. 4. WATIR Testimonials <ul><li>A few testimonials from WATIR website: </li></ul><ul><ul><li>watir rules. It easily outperformed every other automation tool we evaluated… </li></ul></ul><ul><ul><li>the most useful piece of software I’ve ever evaluated… </li></ul></ul><ul><ul><li>watir is by far the most complete web testing framework out there… </li></ul></ul><ul><ul><li>Watir is the most compelling alternative for filling the automated acceptance test need. (Ward Cunningham) </li></ul></ul><ul><ul><li>With watir, we are able to test with ease and ship with confidence. </li></ul></ul><ul><li>And last but not least: </li></ul><ul><ul><li>watir blew my freakin mind. Everything worked, no fuss, no muss, no bother. </li></ul></ul><ul><ul><li>I’m so happy to discover Ruby and Watir. I wanted to run around my office dancing and celebrating. </li></ul></ul>
  5. 5. WATIR Examples <ul><li>ie.link(:id, “lnk1”).click </li></ul><ul><li>ie.button(:id, “btn1”).click </li></ul><ul><li>ie.link(:name, “lnk1”).exists? </li></ul><ul><li>ie.contains_text(‘Welcome’) </li></ul><ul><li>wait_until {@browser.contains_text “Edit&quot;} </li></ul><ul><li>WATIR can find elements by id, name, text, link, XPath, etc… </li></ul><ul><li>WATIR uses the OLE/COM automation interface to control the browser. </li></ul>
  6. 6. Creating a Test DSL with WATIR <ul><li>What is a DSL? </li></ul><ul><ul><li>Domain Specific Language </li></ul></ul><ul><ul><li>a language designed for a specific domain </li></ul></ul><ul><li>Testing DSL </li></ul><ul><ul><li>A language design specifically for browser-based testing. </li></ul></ul>
  7. 7. Test Framework Test Scripts App Specific Test DSL WATIR Test Framework Ruby run-time
  8. 8. Test Script Example <ul><li>launch_myapp ENVIRONMENT, :port=>PORT </li></ul><ul><li>login_as USERNAME, PASSWORD </li></ul><ul><li>goto_page :configuration </li></ul><ul><li>select_tab :partners </li></ul><ul><li>add_new_partner :label=>'TestPartner' </li></ul><ul><li>save_configuration </li></ul>Test Scripts
  9. 9. DSL Example <ul><li>def login_as(user, password) </li></ul><ul><li># enter user name and password </li></ul><ul><li>@browser.text_field(:name, 'member_name').set(user) </li></ul><ul><li>@browser.text_field(:name,'member_password').set(password) </li></ul><ul><li># submit login form </li></ul><ul><li>@browser.form(:id, 'formLogin').submit </li></ul><ul><li>@browser.wait </li></ul><ul><li># verify you have reached the welcome page </li></ul><ul><li>assert @browser.contains_text(&quot;Catalog Data Quick Overview&quot;) </li></ul><ul><li>puts &quot;Successfully logged in.&quot; </li></ul><ul><li>end </li></ul>Test Scripts App Specific Test DSL
  10. 10. Observations <ul><li>Test scripts use very simple application targeted language. </li></ul><ul><li>Only DSL implementation uses WATIR API </li></ul><ul><li>With training QA could write test scripts. </li></ul>
  11. 11. Test Scripts Everywhere… <ul><li>Test scripts can be written before development. </li></ul><ul><ul><li>practice test-driven development. </li></ul></ul><ul><ul><li>embed in Use Cases to achieve testable use cases, executable specifications. </li></ul></ul><ul><li>Defects can be described using a Test Script that reproduces the defect. </li></ul><ul><ul><li>attach script to bugzilla defect. </li></ul></ul>
  12. 12. Recording Scripts <ul><li>Watir Recorder++ </li></ul><ul><li>Firewatir Recorder </li></ul><ul><ul><li>Records user action while user is interacting with the application </li></ul></ul><ul><ul><li>User TestGen4Web XPI for capturing user actions </li></ul></ul><ul><ul><li>Convert user actions to XML </li></ul></ul><ul><ul><li>Convert XML to ruby file for playback using tg4rb gem </li></ul></ul>
  13. 13. WATIR Alternatives <ul><li>Selenium </li></ul><ul><ul><li>Similar open source browser automation framework. </li></ul></ul><ul><ul><li>Scripts are written in custom macro language. </li></ul></ul><ul><li>Commercial Products </li></ul><ul><ul><li>Compuware TestPartner </li></ul></ul><ul><ul><li>Usually based on record-playback techniques </li></ul></ul>
  14. 14. References <ul><li>Watir http://wtr.rubyforge.org </li></ul><ul><li>Firewatir http://code.google.com/p/firewatir </li></ul><ul><li>tg4rb http://code.google.com/p/tg4rb </li></ul><ul><li>TestGen4Web http://developer.spikesource.com/wiki/index.php/Projects:TestGen4Web </li></ul><ul><li>Selenium http://www.openqa.org/selenium/ </li></ul><ul><li>Compuware TestPartner http://www.compuware.com/products/qacenter/375_ENG_HTML.htm </li></ul>

×