Web Application Testing In Ruby - PowerPoint PPT Presentation

1 / 19
About This Presentation
Title:

Web Application Testing In Ruby

Description:

A free, open-source functional testing tool for web applications. ... FireBug (Excellent FireFox extension for identifying HTML elements while writing ... – PowerPoint PPT presentation

Number of Views:454
Avg rating:3.0/5.0
Slides: 20
Provided by: scottdoc
Category:

less

Transcript and Presenter's Notes

Title: Web Application Testing In Ruby


1
Web Application Testing In Ruby
2
What is Watir?
  • A free, open-source functional testing tool for
    web applications.
  • It is a Ruby library which drives Internet
    Explorer the same way people do, clicks links,
    fills in forms, and presses buttons.
  • Watir also checks results, such as whether
    expected text appears on the page.
  • Because its build on Ruby, you have the power to
    connect to databases, read data files, export XML
    and structure your code into reusable libraries.

3
Why use Watir?
  • Free
  • Powerful
  • Simple (easy to use and learn)
  • Excellent Support
  • It uses Ruby, a full-featured object-oriented
    scripting language, rather than a proprietary
    vendorscript.
  • Don't just take our word for it, read what our
    users are saying.

4
What the Users say
  • WATIR is by far the most complete web testing
    framework out here--that doesn't cost an arm and
    a leg. And this forum is the most active and well
    supported that I have seen. You can post a
    question and is just a short period of time get
    someone (most of the time the architects of the
    framework!) who will steer you in the right
    direct, give you a work around to get over any
    roadblocks, or add it to the framework if it
    doesn't currently exist. That is the reason I
    switched and tell everyone interest (and those
    not) that Ruby is the way to go! Save your money,
    get WATIR!

5
What the Users say
  • Ruby is an awesome language and Watir is just
    too cool. It does things that other companies
    (ie. IBM/Rational, Mercury, Segue, et al) charge
    thousands and thousands of dollars a seat for.
    Anyway, now that I'm gettin' the hang of Ruby and
    Watir, I'm starting to automate everything I do
    on the web. Even the simple things like logging
    in to web sites, searches, you name it.

6
What the Users say
  • I was able to write a few unit tests using Watir
    in about 15 minutes and Ive looked at Ruby code
    for all around 48 hours. Granted, I have been
    object-oriented programming for the last four
    years so its not like Ruby looks Russian to me,
    but I wasnt able to figure out JUnit that
    quickly by a long shot.

7
How do I get started?
  • Install Ruby Use the Ruby One-Click Installer
    for Windows.
  • Install the latest Watir Gem
  • Follow this Presentation or Read the User's
    Guide, documentation, examples and tests. Figure
    out your test case, start typing your script, and
    run it!

8
Some Helpful Tools
  • Editors
  • Scite (A good light-weight editor installed with
    Ruby - ruby\scite\scite.exe)
  • RDT (Eclipse plug-in for Ruby, great if you
    need a graphical debugger)
  • Tips for finding/accessing HTML elements
  • IE Developer Tool bar (Lets you explore the HTML
    elements behind the visible elements on a web
    page by clicking on the elements
  • FireBug (Excellent FireFox extension for
    identifying HTML elements while writing scripts.)
  • WATIRSupportsSubElements (Watir API for
    accessing html elements)

9
How do I
  • Navigate the browser?
  • Find elements on the page?
  • Interact with elements on the page?
  • Check output on the page?
  • Create and use Methods?
  • Create formal test cases?

10
Navigating the Browser
  • Always Load the Watir library at the top of
    your script
  • require 'watir'
  • Start IE and navigate to a given URL
  • ie WatirIE.start('http//news.google.com')
  • or..Attach to an existing IE window by title or
    url
  • ie WatirIE.attach(title,'title')
  • ie WatirIE.attach(url,/regex matching url/)
  • Navigate to a different URL
  • ie.goto("http//mentorweb/")
  • Close IE.
  • ie.close

11
Finding Elements
  • Common Functions of the IE object

12
Hows and Whats
  • Hows tell your method how to find the
    element youre looking for. Whats tell your
    method the value for how.
  • Hows
  • name
  • id
  • index
  • value
  • text
  • title
  • Whats
  • String value of how
  • /Regular expression/

13
Interacting with Elements
  • Set the text field (or text area) specified name
    specified value.
  • ie.text_field(name,'name').set('value')
  • Sets the select with to the specified value
  • ie.select_list(name,'name').select('value')
  • Click the button with the specified value
    (label)
  • ie.button(value,'value').click
  • Clicks the link matching 'text'
  • ie.link(text,'text').click
  • Accessing elements in a "frame" or "iframe"
  • ie.frame(name,"someFrame").text_field(name,'name
    ').set('value')

14
Checking Output
  • Get the title of the page
  • ie.title
  • Get all the text displayed on the page
  • ie.text
  • Get all the HTML in the body of the page
  • ie.html
  • Return true if text is displayed on the page
  • ie.contains_text('text')

15
Creating and using Methods
  • Here is an example method for logging into a web
    application. Its two parameters are a user and
    password (both of which have defaults). It
    returns an instance of IE
  • def login(usertest_admin,password
    Password123)
  • ieWatirIE.start(http//someURL.com/login)
  • ie.text_field(name,/user/i).set(user)
  • ie.text_field(name,/password/i).set(password)
  • ie.button(value,/login/i).click
  • return ie
  • End
  • Now we can easily login with the default user..
  • ie login
  • or with a unique user
  • ie login(Fred,flinstone)

16
Creating Formal Test Cases
  • require 'test/unit' includes Ruby's test case
    functionality
  • Require util Assuming our login method is
    saved in util.rb
  • Test cases are contained within classes which
    extend Rubys base test case class
  • class MyTest
  • def setup Optional, will be run before each
    test method.
  • _at_ie login() call our login function.
  • end
  • def test_some_link Test methods must begin with
    "test_
  • _at_ie.link(text,some_link).click click on
    some link
  • verify that the proper page loaded
  • assert(_at_ie.contains_text(My Some Link Page))
  • end
  • def teardown Optional, will be run after each
    test method.
  • _at_ie.close
  • end

17
Debugging with IRB
  • IRB Interactive Ruby Shell
  • Command line-like interface that allows immediate
    running of Ruby script
  • Great for debugging one line at a time, rather
    then having to run through an entire script
  • Great for testing single lines
  • Try ruby out using an online IRB. This is a great
    way to learn ruby basics!

18
Watir Ruby Resources
  • Watir
  • Watir main site http//wiki.openqa.org/display/WT
    R/
  • Watir user guide wtr.rubyforge.org/watir_user_gui
    de.html
  • Watir API wtr.rubyforge.org/rdoc/index.html
  • Mailing List rubyforge.org/mailman/listinfo/wtr-g
    eneral
  • Project site http//wiki.openqa.org/display/WTR/
  • User Contributions/examples http//wiki.openqa.or
    g/display/WTR/Contributions
  • Watir FAQ http//wiki.openqa.org/display/WTR/FAQ
  • Ruby
  • Ruby site http//ruby-lang.org
  • Ruby docs http//ruby-doc.org/
  • Ruby Quickstart ruby-lang.org/en/documentation/qu
    ickstart/

19
Thats it!
  • Note All information contained in the
    presentation was compiled from documentation on
    the official Watir site, or from its mailing
    list.
Write a Comment
User Comments (0)
About PowerShow.com