introduction to ruby watir (web application testing in ruby)

Post on 10-May-2015

905 Views

Category:

Software

2 Downloads

Preview:

Click to see full reader

DESCRIPTION

This involves the presentation of fundamentals/basics of Ruby-WATIR (Web Application Testing In Ruby) for the tester to automate there testing methods and steps.

TRANSCRIPT

Introduction to Ruby-Watir

PRESENTED BY: SUBHASISH PATTANAIKSOFTWARE QUALITY ANALYST

MINDFIRE SOLUTIONS

Contents

What is Watir?

What WATIR is not...

What is Ruby?

How does Watir works?

Why Watir?

Setting up WATIR

Learning WATIR

IDE's for Ruby-Watir

Small Scripts

What is WATIR?

Web Application Testing In Ruby

It is a library for the Ruby language which drives Firefox, Google Chrome, Internet Explorer the same way people do;

clicks links,

fills in forms,

and presses buttons.

Watir can also check results, such as whether expected text appears on the page.

It can be used to test all types of web applications (ASP.Net, JSP, PHP, Rails, etc…)

Open Source – written by Bret Pettichord, Paul Rogers and many other contributors.

What WATIR is not...Watir is not a record/playback tool.However, there are several recorders “out there”

WatirMaker

Watir WebRecorder

Webmetrics RIA Script Recorder (most recent discussion…they are considering open sourcing their application)

Watir is not a link checker.However, you can easily write your own link checker and

customize it to your specific needs.

Watir is not a test case management tool.However, you can write one in Ruby if desired.

Doesn’t test Flash or Applets.

What is Ruby?

Full featured Object Oriented scripting languageMade “famous” for it’s web application framework Rails. (Ruby on

Rails)

Interpreted rather than compiledWritten by Matz (Yukihiro Matsumoto)Started in 1994

Written in CWill work on any platform that has a C compiler

WindowsLinux

How does Watir works?

Uses the COM interface of Internet Explorer (IE)

Allows an external program to control IE

Similar interfaces exist for Word, Excel, PowerPoint and Outlook.

Full access to the contents of an HTML page

Provides different ways to access objects

The Big Question : Why Watir?

Why Watir? (contd...)

As a testing tool: It’s as robust & sophisticated as ‘professional’ tools such as Rational, Mercury & Segue.

As a library of a programming language [Ruby ] : It’s powerful.

(You have the power to connect to databases, read data files, export XML, structure your code into reusable libraries, and pretty much anything else you can think of…)

No “Vendor-script”

It’s simple – elegant – INTUITIVE

It has a supportive online community for when you get ‘stuck’.

Setting up WATIR

Learning WATIR : Getting Started

As you start to get into Ruby/Watir you’ll want some Good information at your fingertips!

Introductory Documentation:Watir homepage: http://watir.comWatir User Guide: http://en.wikipedia.org/wiki/watir

Books:Everyday Scripting with Ruby: for Teams, Testers, and You:

http://pragprog.com/book/bmsft/everyday-scripting-with-rubyProgramming Ruby (Online Book):

http://ruby-doc.com/docs/ProgrammingRuby/

Learning WATIR : More In-Depth

Forums:

Watir General Forum (now on Google Groups): http://groups.google.com/group/watir-general?hl=en

Watir Search (web interface that searches 7 Watir sites): https://www.google.com/cse/home?cx=007267089725385613265:gmydx5gtw6u

Online Ruby Information: http://www.ruby-doc.org/

Watir Book : https://github.com/watir/watirbook

Development Environment's(IDE's)

for RubyUse any text editor as an IDE:

ScITE (Free)

Included with your ruby download.

Notepad ++(Free)

Eclipse (using RDT Plugin)

http://rubyeclipse.sourceforge.net/

Ruby In Steel (Free - $199) (Add-on to VS.Net )

http://www.sapphiresteel.com

Komodo IDE ($295) / Komodo Edit (Free)

http://www.activestate.com

Using Ruby's Interactive Command

Interpreter (IRB) What is it?

Interactive Ruby.

It evaluates Ruby expressions from the Terminal.

Used To:

Run quick experiments to see if things will work in your tests

– irb (main) : 001 : 0> require 'watir'.– irb (main) : 002 : 0> require 'watir-webdriver'.– irb (main) : 003 : 0> browser = Watir::Browser.new'.– irb (main) : 004 : 0> browser.goto 'http://google.com'

Let's Get Started..

It’s time to turn on the Watir!

Anatomy of Watir Script

# Loads the watir gemsrequire 'watir'# Loads all the gems required to drive firefox and chromerequire 'watir-webdriver'# To open a new browser(firefox)browser = Watir::Browser.new :firefox# Navigate to the below URLbrowser.goto 'http://ourgoalplan.com/'# Identify the field to which data is to be inserted and enter the valuebrowser.text_field(:name => 'txtName').set 'subhasish.pattanaik'browser.text_field(:name => 'txtPassword').set 'subh_2727'# To click the buttonbrowser.button( :id => 'btnLogin').click# To enter the goals in the Text areabrowser.text_field( :id => 'ucAddGoal_txtAddGoal').set '[CIRRATA-

WP] : TESTING + ISSUES REPORTING[EST - 2HRS]' + "\n" + '[COMMETTE] : TESTING + ISSUES REPORTING[EST - 2HRS]'

# To click on the Add Goal buttonbrowser.button( :id => 'ucAddGoal_btnAddGoal').click

Use Watir

Using Watir API is very easy.

Reference the Watir API using the keyword 'require' and start coding.

require 'watir'require 'watir-webdriver'browser = Watir::Browser.new :firefox

Web Pages are all about Objects

Web pages are developed with objects:

Links, buttons, tables, drop-down boxes, forms, frames, etc.

Watir scripts need to access these objects & manipulate them just as a user would.

Clicking, submitting, typing, selecting, etc…

Manipulating Web Page Objects:Link

Manipulating Web Page Objects:Checkbox

Manipulating Web Page Objects:Radio Buttons

Manipulating Web Page Objects:Selection Boxes

Manipulating Web Page Objects:Text Fields

Manipulating Web Page Objects:Buttons

A Closer Look... at the structure

browser.button(:value, "Click Me").click

[Variable] . [method] (: [element] , “ [unique identifier]” . [method]

Test Automation is MORE than Identifying

Objects

Identifying objects is currently the most time consuming part of creating your test scripts…

However, after your objects have been identified & manipulated: you want to “Test” them!

You’ll want to create “PASS” or “FAIL” scenarios.

…This is the most sophisticated part of your scripts. Will learn more on this

in next seminar...

Congratulations! You are on your Way

…to programming the Ruby-Watir way !!

References

1. https://github.com/watir/watirbook

2. http://watir.com/

3. http://watir.com/examples/

4. http://www.thoughtworks.com/insights/articles/automated- testing-using-ruby-and-watir

5. http://watirwebdriver.com/

6. http://www.rubywatir.com/

7. http://en.wikipedia.org/wiki/Watir

Thank You Any Queries???

top related