introduction to ruby watir (web application testing in ruby)

29
Introduction to Ruby- Watir PRESENTED BY: SUBHASISH PATTANAIK SOFTWARE QUALITY ANALYST MINDFIRE SOLUTIONS

Upload: mindfire-solutions

Post on 10-May-2015

905 views

Category:

Software


2 download

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

Page 1: Introduction To Ruby Watir (Web Application Testing In Ruby)

Introduction to Ruby-Watir

PRESENTED BY: SUBHASISH PATTANAIKSOFTWARE QUALITY ANALYST

MINDFIRE SOLUTIONS

Page 2: Introduction To Ruby Watir (Web Application Testing In Ruby)

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

Page 3: Introduction To Ruby Watir (Web Application Testing In Ruby)

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.

Page 4: Introduction To Ruby Watir (Web Application Testing In Ruby)

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.

Page 5: Introduction To Ruby Watir (Web Application Testing In Ruby)

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

Page 6: Introduction To Ruby Watir (Web Application Testing In Ruby)

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

Page 7: Introduction To Ruby Watir (Web Application Testing In Ruby)

The Big Question : Why Watir?

Page 8: Introduction To Ruby Watir (Web Application Testing In Ruby)

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’.

Page 9: Introduction To Ruby Watir (Web Application Testing In Ruby)

Setting up WATIR

Page 10: Introduction To Ruby Watir (Web Application Testing In Ruby)

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/

Page 11: Introduction To Ruby Watir (Web Application Testing In Ruby)

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

Page 12: Introduction To Ruby Watir (Web Application Testing In Ruby)

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

Page 13: Introduction To Ruby Watir (Web Application Testing In Ruby)

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'

Page 14: Introduction To Ruby Watir (Web Application Testing In Ruby)

Let's Get Started..

It’s time to turn on the Watir!

Page 15: Introduction To Ruby Watir (Web Application Testing In Ruby)

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

Page 16: Introduction To Ruby Watir (Web Application Testing In Ruby)

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

Page 17: Introduction To Ruby Watir (Web Application Testing In Ruby)

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…

Page 18: Introduction To Ruby Watir (Web Application Testing In Ruby)

Manipulating Web Page Objects:Link

Page 19: Introduction To Ruby Watir (Web Application Testing In Ruby)

Manipulating Web Page Objects:Checkbox

Page 20: Introduction To Ruby Watir (Web Application Testing In Ruby)

Manipulating Web Page Objects:Radio Buttons

Page 21: Introduction To Ruby Watir (Web Application Testing In Ruby)

Manipulating Web Page Objects:Selection Boxes

Page 22: Introduction To Ruby Watir (Web Application Testing In Ruby)

Manipulating Web Page Objects:Text Fields

Page 23: Introduction To Ruby Watir (Web Application Testing In Ruby)

Manipulating Web Page Objects:Buttons

Page 24: Introduction To Ruby Watir (Web Application Testing In Ruby)

A Closer Look... at the structure

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

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

Page 25: Introduction To Ruby Watir (Web Application Testing In Ruby)

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...

Page 26: Introduction To Ruby Watir (Web Application Testing In Ruby)

Congratulations! You are on your Way

…to programming the Ruby-Watir way !!

Page 27: Introduction To Ruby Watir (Web Application Testing In Ruby)

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

Page 28: Introduction To Ruby Watir (Web Application Testing In Ruby)

Thank You Any Queries???

Page 29: Introduction To Ruby Watir (Web Application Testing In Ruby)