Automated Web Testing With WATIR

download Automated Web Testing With WATIR

of 17

Transcript of Automated Web Testing With WATIR

  • 8/8/2019 Automated Web Testing With WATIR

    1/17

    2006 Avik Sengupta. All Rights Reserved. 1

    WATIR

    Automated Web testing using WATIR

    Avik Sengupta

  • 8/8/2019 Automated Web Testing With WATIR

    2/17

    2006 Avik Sengupta. All Rights Reserved. 2

    Automated Web Testing

    You would never writeserver side code withoutautomated tests

    So why write front end codewithout them?

    Agile Gibbon

    Hylobates agilis

  • 8/8/2019 Automated Web Testing With WATIR

    3/17

    2006 Avik Sengupta. All Rights Reserved. 3

    Why Watir

    It's a free Open Source tool

    A very active and growing community

    Uses Ruby, a full-featured object-oriented

    scripting language, rather than a proprietaryvendorscript.

    Powerful and easy to use.

    Delighted users ...

  • 8/8/2019 Automated Web Testing With WATIR

    4/17

    2006 Avik Sengupta. All Rights Reserved. 4

    Watir Testimonials

    "Watir Rocks! Truly awesome!!" Shashank Date

    "Watir is the most compelling alternative [to Fit] forfilling the automated acceptance testing need."

    Ward Cunningham"I've been trying to find the Holy Grail of AutomatedWeb UI Testing....And the one I'm currentlyenamored with is Watir. Scott Hanselman

    "I wanted to run around my office dancing andcelebrating." Beth Ferguson

    http://wtr.rubyforge.org/wiki/wiki.pl?WatirTestimonials

  • 8/8/2019 Automated Web Testing With WATIR

    5/17

    2006 Avik Sengupta. All Rights Reserved. 5

    Creation and History

    2002 Wasserman creates SamieA Perl COM/DOM driverRefused a WinRunner license

    early 2003 Morris creates IECA Ruby COM/DOM Driver

    Inspired by SamieMay 2003 Marick & Pettichord

    First teach Scripting for Testers, using RubyIEC is very popular with studentsContinue to teach this class publicly, adapting IEC to studentreactions

    Oct 2003 Web Testing with Ruby project foundedIncludes both IEC and the Scripting class materialsRogers contributes another Ruby COM/DOM driver

    Aug 2004 Watir launched by Pettichord & RogersA new Ruby COM/DOM Driver based on Test-DrivenDevelopment

    Jan 2005 Watir 1.0 released

  • 8/8/2019 Automated Web Testing With WATIR

    6/17

    2006 Avik Sengupta. All Rights Reserved. 6

    How Watir Works

    Browser Automation

    Test drive the browser

    Use IE OLE/COM

    interface

    Web Server

    Internet

    Explorer

    Watir &

    RubyAutomation

    Interface

  • 8/8/2019 Automated Web Testing With WATIR

    7/17 2006 Avik Sengupta. All Rights Reserved. 7

    Document Object Model (DOM)

    DOM is ...A standard model for elements of a web page

    Used by client-side JavaScript

    Supported by IE, Mozilla, FireFox and other browsersIE also provides access to the DOM via OLE/COM

    Use WATIR to access page elements via theDOM

  • 8/8/2019 Automated Web Testing With WATIR

    8/17 2006 Avik Sengupta. All Rights Reserved. 8

    DOM

  • 8/8/2019 Automated Web Testing With WATIR

    9/17 2006 Avik Sengupta. All Rights Reserved. 9

    Watir Basics

    require 'watir'

    ie = Watir::IE.start('http://localhost:8080')

    ie.title

    ie.text_field(:name, 'name').set('value')

    ie.button(:value, 'value').click

    ie.contains_text('text')

    assert_equal(expected, test_method)

    assert_match(regexp, test_method)

    assert(expression)

  • 8/8/2019 Automated Web Testing With WATIR

    10/17 2006 Avik Sengupta. All Rights Reserved. 10

    Show me the Code!

    Demo WATIR

  • 8/8/2019 Automated Web Testing With WATIR

    11/17 2006 Avik Sengupta. All Rights Reserved. 11

    Caveats

    Only works on Windows/IE

    Careful working with modal windows

  • 8/8/2019 Automated Web Testing With WATIR

    12/17 2006 Avik Sengupta. All Rights Reserved. 12

    Alternatives COM/DOM Drivers

    Samie Perlhttp://samie.sourceforge.net

    Win32-IE-Mechanize Perlhttp://search.cpan.org/dist/Win32-IE-Mechanize/

    Jiffie Javahttp://jiffie.sourceforge.netPamie Python

    http://pamie.sourceforge.net

    IEUnit JavaScript

    http://ieunit.sourceforge.netIETest C#http://ietest.sourceforge.net

    http://samie.sourceforge.net/http://search.cpan.org/dist/Win32-IE-Mechanize/http://jiffie.sourceforge.net/http://pamie.sourceforge.net/http://ieunit.sourceforge.net/http://ietest.sourceforge.net/http://ietest.sourceforge.net/http://ieunit.sourceforge.net/http://ieunit.sourceforge.net/http://pamie.sourceforge.net/http://jiffie.sourceforge.net/http://search.cpan.org/dist/Win32-IE-Mechanize/http://samie.sourceforge.net/
  • 8/8/2019 Automated Web Testing With WATIR

    13/17 2006 Avik Sengupta. All Rights Reserved. 13

    Alternatives Protocol Drivers

    Simulate a Web Browser

    HttpUnit Javahttp://httpunit.sf.net

    jWebUnit Javahttp://jwebunit.sf.net

    HTMLUnit Javahttp://htmlunit.sf.net

    WWW-Mechanize Perlhttp://search.cpan.org/dist/WWW-Mechanize/

    All open-source and commercial load/performance testing tools are protocol drivers

    Technology is limited for functional testing because ofinability to test JavaScript and

    browser

    http://httpunit.sf.net/http://jwebunit.sf.net/http://htmlunit.sf.net/http://search.cpan.org/dist/WWW-Mechanize/http://search.cpan.org/dist/WWW-Mechanize/http://htmlunit.sf.net/http://jwebunit.sf.net/http://httpunit.sf.net/
  • 8/8/2019 Automated Web Testing With WATIR

    14/17 2006 Avik Sengupta. All Rights Reserved. 14

    Alternatives Selenium

    Tests run in the browser using bot

    Requires installation on ServerSupports multiple browsers/OS

    Selenium workshop by Paul Hammanttomorrow at 2

  • 8/8/2019 Automated Web Testing With WATIR

    15/17 2006 Avik Sengupta. All Rights Reserved. 15

    Questions?

  • 8/8/2019 Automated Web Testing With WATIR

    16/17 2006 Avik Sengupta. All Rights Reserved. 16

    More Info

    Main Watir Site

    http://wtr.sourceforge.net

    User Guide

    http://wtr.rubyforge.org/watir_user_guide.html

    Mailing Listhttp://rubyforge.org/mailman/listinfo/wtr-general

    Ruby

    http://www.ruby-lang.org/en/

    http://www.rubycentral.com/book/index.htmlhttp://www.pragmaticprogrammer.com/titles/ruby/index.html

    This Presentation

    http://www.sengupta.net/talks/

    Acknowledgement: Some material courtesy Brett Pettichord

    (http://wtr.rubyforge.org/s101/doc/)

    http://www.ruby-lang.org/en/http://www.rubycentral.com/book/index.htmlhttp://www.sengupta.net/talks/http://www.sengupta.net/talks/http://www.sengupta.net/talks/http://www.sengupta.net/talks/http://www.rubycentral.com/book/index.htmlhttp://www.ruby-lang.org/en/
  • 8/8/2019 Automated Web Testing With WATIR

    17/17 2006 Avik Sengupta All Rights Reserved 17

    Dependencies & Installation

    Install RubyOn windows, use the One Click Installer

    http://rubyforge.org/frs/?group_id=167

    Install Watirgem install watir

    OR

    http://rubyforge.org/frs/?group_id=104Enjoy!