27
Sumanth Krishna. A www.sumanthkrishna.com Web Application Test In Ruby

WATIR Presentation - Sumanth Krishna. A

Embed Size (px)

DESCRIPTION

Web Application Test In Ruby, is a testing framework for the web applications. Since it's built on ruby it would take the advantage of object oriented principles of ruby and makes the regression/functional testing very very simple. This presentation aims to introduce the WATIR, assists in installing and also testing with a simple test case.

Citation preview

Page 1: WATIR Presentation - Sumanth Krishna. A

Sumanth Krishna. Awww.sumanthkrishna.com

Web Application Test In Ruby

Page 2: WATIR Presentation - Sumanth Krishna. A

AgendaIntroducing the topicDiscussion on Testing frameworks/tools and

it’s necessityRubyInstallationsArchitectureTestcasesScope

Page 3: WATIR Presentation - Sumanth Krishna. A

TAG CLOUDruby Apache Nginx assertions

install webserver FireWatir temp-

user WATIR goto html DOM

web-applications opensourcetests

Assertions get_string firefox-addon

click hudson SVN COM open-source IE gems open-QA ruby regression loadrunner mercury automatio deployment browers tools

WATIR html DOM recorder telnet

Page 4: WATIR Presentation - Sumanth Krishna. A

PrerequisitesCan you believe you really don’t need any

special skills to implement this!

Page 5: WATIR Presentation - Sumanth Krishna. A

What is WATIR?open-source functional testing tool for web-

applicationsSimulate the user actions (filling/submitting

forms…)Drives Internet Explorer browser

FireWatir – for FireFoxRuby based

Various assertions (content-based)Connects to databasesReading data filesExporting data (xml/html/excel…)

Page 6: WATIR Presentation - Sumanth Krishna. A

Why use WATIR?FreePowerfulSimple (easy to use and learn)Excellent SupportStrongest Presence

Watir/Watin/Watij [Web Application Testing In Ruby/.NET/Java ]

Huge resource of supporting tools – Firewatir, Watir Recorder ++, Wet, Cubictest,

Visual Studio

Page 7: WATIR Presentation - Sumanth Krishna. A

Is not?Watir is not a record/playback tool.

However, there are several recorders “out there”WatirMakerWatir WebRecorderWebmetrics RIA Script Recorder (most recent discussion…

they are considering open sourcing their application)

Watir is not a link checkerHowever, 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.(underwork)

Page 8: WATIR Presentation - Sumanth Krishna. A

IE-WATIR

Web Application

AutomationInterface

Use the OLE/COM Automation interface to Internet Explorer

IE Watir/Ruby

DO

M

Page 9: WATIR Presentation - Sumanth Krishna. A

FF-FireWATIR

Web Application

AutomationInterface

FF FireWatir/Ruby

DO

M

JSSh

Page 10: WATIR Presentation - Sumanth Krishna. A

Browser Support

IE COM

Test Script

Component 1

FF JSSH Apple Events V8 Debugger Dragonfly

Component 2 Component 3 Component 4

Watir APIWatir API

Page 11: WATIR Presentation - Sumanth Krishna. A

Installing: Windows Install Ruby: Use the Ruby one-click installer for windows Install the latest gem watir (ruby packages are called gems)

gem install watirAnd you find the following gems installing…

Successfully installed xml-simple-1.0.11Successfully installed s4t-utils-1.0.4Successfully installed builder-2.1.2Successfully installed user-choices-1.1.6Successfully installed commonwatir-1.6.2Successfully installed firewatir-1.6.2 (to support Firefox)Successfully installed watir-1.6.2Successfully installed win32-api-1.3.0-x86-mswin32-60Successfully installed windows-api-0.3.0Successfully installed rubyforge-1.0.210 gems installed

Installation done… let’s move ahead

Page 12: WATIR Presentation - Sumanth Krishna. A

What Next?Since we are here to test the web-

application 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?

Page 13: WATIR Presentation - Sumanth Krishna. A

Step by StepNavigate to the browser#Always Load the Watir library at the top of

your scriptrequire ‘watir’

Start IE and navigate to a given/different URLIE = Watir::IE.start(‘http://www.qvnatel.com’)IE.goto(“http://free-opensource.qvantel.net/

mediawiki//index.php/Main_Page ”)IE.close

Page 14: WATIR Presentation - Sumanth Krishna. A

Finding <HTML> ElementsTextBox IE.text_field(how, what)

Button IE.button(how, what)

DropDownList IE.select_list(how, what)

CheckBox IE.checkbox(how, what)

RadioButton IE.radio(how, what)

HyperLink IE.link(how, what)

Form IE.form(how, what)

Frame IE.frame(how, what)

And many, many more (div, label, image, etc…)…

Page 15: WATIR Presentation - Sumanth Krishna. A

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 valueie.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,'na

me').set('value')

Page 16: WATIR Presentation - Sumanth Krishna. A

Closer view

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

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

Page 17: WATIR Presentation - Sumanth Krishna. A

Checking Output

#Get the title of the pageie.title

#Get all the text displayed on the pageie.text

#Get all the HTML in the body of the pageie.html

#Return true if ‘text’ is displayed on the pageie.contains_text('text')

Page 18: WATIR Presentation - Sumanth Krishna. A
Page 19: WATIR Presentation - Sumanth Krishna. A

Ruby advantageSince WATIR is ruby based web application

testing framework, we can customize the script according to our needs.

Taking Ruby’s Object Oriented concepts, create more dynamic/customized scripts

Use classes & methods effectivelyAccess even the database to validate the

data

Page 20: WATIR Presentation - Sumanth Krishna. A

Test::Unit Assertions

Page 21: WATIR Presentation - Sumanth Krishna. A

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 IEdef login(user=“test_admin”,password = “Password123”)

ie=Watir::IE.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).clickreturn ie

end

#Now we can easily login with the default user.. ie = login #or with a unique user ie = login(“Fred”,”flinstone”)

Page 22: WATIR Presentation - Sumanth Krishna. A

Full Fledge Test Case 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 Ruby’s base test case classclass MyTest < Test::Unit::TestCase

def setup #Optional, will be run before each test method. @ie = login() #call our login function.

end

def test_some_link #Test methods must begin with "test_“@ie.link(:text,”some_link”).click #click on some link

#verify that the proper page loadedassert(@ie.contains_text(“My Some Link Page”))

end

def teardown #Optional, will be run after each test [email protected]

endend

Page 23: WATIR Presentation - Sumanth Krishna. A

Installing: Ubuntu Install Ruby:

sudo apt-get install ruby Install the latest gem firewatir (ruby packages are called gems)

sudo gem install firewatirAnd you find the following gems installing…

Successfully installed xml-simple-1.0.11Successfully installed s4t-utils-1.0.4Successfully installed builder-2.1.2Successfully installed user-choices-1.1.6Successfully installed commonwatir-1.6.2Successfully installed firewatir-1.6.2Successfully installed rubyforge-1.0.27 gems installed (3gems to support IE/Windows environment are not

installed)

Installation done… let’s move ahead

Page 24: WATIR Presentation - Sumanth Krishna. A

Tweaks/TipsWhile working on Linux platform need to

specifyrequire “rubygems” at the top of test case

ff = FireWatir::Firefox.newStart firefox in jssh mode

For Windows:Close instances of firefox (if any)Type “firefox.exe –p –jssh” in the “Run”

ie = Watir::IE.new

Page 25: WATIR Presentation - Sumanth Krishna. A

ScopeUsing Watir for all web applicationsIntegrate it with Automation/Building

process

Page 26: WATIR Presentation - Sumanth Krishna. A

References Watir

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

Watir main site: http://wiki.openqa.org/display/WTR/ Watir user guide: wtr.rubyforge.org/watir_user_guide.htmlWatir API: wtr.rubyforge.org/rdoc/index.htmlMailing List: rubyforge.org/mailman/listinfo/wtr-generalProject site: http://wiki.openqa.org/display/WTR/User Contributions/examples: http://wiki.openqa.org/display/WTR/ContributionsWatir FAQ: http://wiki.openqa.org/display/WTR/FAQ

Watir Recorderhttp://www.hanselman.com/blog/

IntroducingWatirMakerRecordingForRubybasedWatir.aspx http://www.hanselman.com/blog/NewReleaseOfWatirMakerNowWatirRecorder.aspx

FireWatirSource: http://code.google.com/p/firewatir/wiki/Firewatir

RubyRuby site: http://ruby-lang.orgRuby docs: http://ruby-doc.org/Ruby Quickstart: ruby-lang.org/en/documentation/quickstart/

Page 27: WATIR Presentation - Sumanth Krishna. A

Thanks

[email protected]