Web Testing with Ruby and Watir - PowerPoint PPT Presentation

1 / 44
About This Presentation
Title:

Web Testing with Ruby and Watir

Description:

body bgcolor='antiquewhite' img src='BoiseCodeCamp-round.gif' h2 Version 2.0 /h2 ... body bgcolor='lightsteelblue' img src='BoiseCodeCamp-round.gif' ... – PowerPoint PPT presentation

Number of Views:1334
Avg rating:3.0/5.0
Slides: 45
Provided by: sis69
Category:
Tags: bgcolor | ruby | testing | watir | web

less

Transcript and Presenter's Notes

Title: Web Testing with Ruby and Watir


1
Web Testing with Ruby and Watir
2
What is Watir?
Web Application Testing In Ruby
3
Open Source Library (gem)
4
Watir drives Internet Explorer
Watir Library (gem)
Internet Explorer
COM
5
How does Watir differ from other web test methods?
  • Is not based on object position
  • Not an HTTP testing method

6
The Ruby Language
  • Dynamic
  • Easy to understand syntax
  • Easy to use interpreter
  • Object Oriented
  • Powerful class libraries

7
Enough Already!! Lets get to the Code!!
8
Webpage Example 1
ltHtmlgt ltheadgt lttitlegtBoise Code Camp -
Testing with Ruby and Watirlt/titlegt lt/headgt ltbody
bgcolor"antiquewhite"gt ltimg src"BoiseCodeCamp-
round.gif"gt lth2gtVersion 2.0lt/h2gt ltbrgt lth1gtWelcome
to Boise Code Camp 2007lt/h1gt lth3gtTesting Web
Applications with Ruby and Watirlt/h3gt lt/bodygt lt/h
tmlgt
9
Watir Test Example 1
Load the library and Create Reference to
Library object require 'watir' include Watir
Create a new IE object ie IE.new Go to the
web site ie.goto( "http//localhost/Page1.asp
) Check for text on the web page if
ie.contains_text( "Testing Web Applications with
Ruby and Watir ) puts "Test Passed Page 1
Validated" end
10
Testing Links on a Web Page
11
WebPage Example 2
ltimg src"BoiseCodeCamp-round.gif"gt lth2gtVersion
2.0lt/h2gt ltbrgt lth1gtWelcome to Boise Code Camp
2007lt/h1gt lth3gtTesting Web Applications with Ruby
and Watirlt/h3gt ltbrgt lta id"1" name"msnlink"
href"http//www.msn.com"gtMSNlt/agtltbrgt lta id"2"
name"yahoolink" href"http//www.yahoo.com"gtYahoo
lt/agtltbrgt lta id"3" name"slashdotlink"
href"http//slashdot.org/"gtSlashdotlt/agtltbrgt lta
id"4" name"ecode" href"http//www.elegantcode.c
om/"gtElegantcodelt/agtltbrgt lta id"5" namebplink"
href"http//www.pettichord.com/"gtBret
Pettichordlt/agtltbrgt lt/bodygt lt/htmlgt
12
Watir Test Example 2
Load the library and Create Reference to
Library object require 'watir' include Watir
Create a new IE object ie IE.new Go to the
web site ie.goto( "http//localhost/Page2.asp
) Verify the existance of a link if ie.link(
text, "Slashdot ).exists? puts "Test Passed
Link with Slashdot as text found" end if
ie.link( text, /Code/ ).exists? puts "Test
Passed Link with the word code found" end
13
Watir Test Example 2 cont.
if ie.link( url, /yahoo/ ).exists? puts "Test
Passed Link with the word yahoo found" end puts
"Display the text for link 1 " ie.link(
index, 1 ).text if ie.link( id, "1 ).text
"MSN" puts "Test Passed Link with id 1 and
text containing MSN found" end if ie.link(
index, 1 ).href "http//www.msn.com") puts
"Test Passed Link index 1 has http//www.msn.com
as href" end Click on a link ie.link( text,
"Slashdot ).click if ie.link( text, "Subscribe
).exists? puts "Test Passed Subscribe Link on
slashdot found" end
14
Text Boxes Buttons
15
WebPage Example 3
ltHtmlgt ltheadgt lttitlegtBoise Code Camp -
Testing with Ruby and Watirlt/titlegt lt/headgt ltbody
bgcolor"antiquewhite"gt ltimg src"BoiseCodeCamp-
round.gif"gt lth2gtVersion 2.0lt/h2gt ltbrgt lth1gtWelcome
to Boise Code Camp 2007lt/h1gt lth3gtTesting Web
Applications with Ruby and Watirlt/h3gt ltpgtEnter
something interesting in the text box and click a
button!lt/pgt ltform name"input" action"page3next.a
sp" method"post"gt ltpgtltInput type"text"
name"searchbox"gtlt/pgt ltpgtltInput type"submit"
value"submit"gtlt/pgt lt/formgt lt/bodygt lt/htmlgt
16
Watir Test Example 3
Load the library and Create Reference to
Library object require 'watir' include Watir
Create a new IE object ie IE.new Go to the
web site ie.goto( "http//localhost/Page3.asp
) Add text to a text box ie.text_field( name,
"searchbox ).set( "Information ) Click on a
button ie.button( value, "submit ).click
17
Watir Test Example 3 cont.
Check that the form exists if ie.form( name,
"input ).exists? puts "Test Passed Form input
found" end Click the button based the form it
is in ie.form( name, "input ).button( value,
"submit ).click
18
Images
19
WebPage Example 4
ltHtmlgt ltheadgt lttitlegtBoise Code Camp -
Testing with Ruby and Watirlt/titlegt lt/headgt ltbody
bgcolor"lightsteelblue"gt ltimg
src"BoiseCodeCamp-round.gif"gt lth2gtVersion
2.0lt/h2gt ltbrgt lth1gtWelcome to Boise Code Camp
2007lt/h1gt lth3gtTesting Web Applications with Ruby
and Watirlt/h3gt ltimg name"watergraphic"
src"112_Water_Faucet_ph.jpg" alt"Image of water
faucet"/gt lta href"page3next.asp"gtltimg alt"Image
Button" src"bgdb.gif"/gtlt/agt lt/bodygt lt/htmlgt
20
Watir Web Test Example 4
Load the library and Create Reference to
Library object require 'watir' include Watir
Create a new IE object ie IE.new Go to the
web site ie.goto( "http//localhost/Page4.asp
) Check that the image exists if ie.image(
src, /Water/ ).exists? puts "Test Passed
Found a graphic with the word Water in the source
filename" end
21
Watir Web Test Example 4 cont
if ie.image( name, "watergraphic ).exists?
puts "Test Passed Found a graphic with the name
watergraphic" end if ie.image( alt, "Image of
water faucet ).exists? puts "Test Passed
Found a graphic with Image of water faucet as alt
text" end Click the image button ie.image(
src, /bgdb/ ).click Check the contents of the
new page if ie.contains_text( "I hope you Enjoy
Code Camp! ) puts "Test Passed Text found" end
22
Check Boxes
23
WebPage Example 5
ltHtmlgt ltheadgt lttitlegtBoise Code Camp -
Testing with Ruby and Watirlt/titlegt lt/headgt ltbody
bgcolor"cadetblue"gt ltimg src"BoiseCodeCamp-rou
nd.gif"gt lth2gtVersion 2.0lt/h2gt ltbrgt lth1gtWelcome to
Boise Code Camp 2007lt/h1gt lth3gtTesting Web
Applications with Ruby and Watirlt/h3gt ltform
action"page3next.asp" method"post"gt
ltpgtltInput type"checkbox" name"checkthebox"gtlt/pgt
ltpgtltInput type"submit" value"submit"gtlt/pgt lt/
formgt lt/bodygt lt/htmlgt
24
Watir Test Example 5
Go to the web site ie.goto("http//localhost/
Page5.asp") Check that the checkbox
exists if ie.checkbox( name, "checkthebox").exist
s? puts "Test Passed The check box
exists" end Check the checkbox ie.checkbox(
name, "checkthebox ).set Un-Check the
checkbox ie.checkbox( index, 1 ).set( false )
25
Radio Buttons
26
WebPage Example 6
ltHtmlgt ltheadgt lttitlegtBoise Code Camp -
Testing with Ruby and Watirlt/titlegt lt/headgt ltbody
bgcolor"antiquewhite""gt ltimg
src"BoiseCodeCamp-round.gif"gt lth2gtVersion
2.0lt/h2gt ltbrgt lth1gtWelcome to Boise Code Camp
2007lt/h1gt lth3gtTesting Web Applications with Ruby
and Watirlt/h3gt ltform action"page3next.asp"
method"post"gt ltpgtOption 1ltInput type"radio"
name"radiobutton1"gtlt/pgt ltpgtOption 2ltInput
type"radio" name"radiobutton2"gtlt/pgt
ltpgtOption 3ltInput type"radio" name"radiobutton3"
gtlt/pgt ltpgtltInput type"submit"
value"submit"gtlt/pgt lt/formgt lt/bodygt lt/htmlgt
27
Watir Test Example 6
Go to the web site ie.goto("http//localhost/
Page6.asp") Check that the radio button
exists if ie.radio( name, "radiobutton1").exists?
puts "Test Passed Radio button found" end
Change the state of the Radio Buttons ie.radio(
name, "radiobutton1 ).set ie.radio( name,
"radiobutton3 ).set
28
Selection Boxes
29
Webpage Example 7
ltHtmlgt ltheadgt lttitlegtBoise Code Camp -
Testing with Ruby and Watirlt/titlegt lt/headgt ltimg
src"BoiseCodeCamp-round.gif"gt lth2gtVersion
2.0lt/h2gt lth1gtWelcome to Boise Code Camp
2007lt/h1gt lth3gtTesting Web Applications with Ruby
and Watirlt/h3gt ltform action"page3next.asp"
method"post"gt ltselect name"dropdown"gt
ltoption value"1" selected gtChicken
ltoption value"2"gtBeef ltoption
value"3"gtVegetarian lt/selectgt ltpgtltInput
type"submit" value"submit"gtlt/pgt lt/formgt lt/bodygt
lt/htmlgt
30
Watir Test Example 7
Load the library and Create Reference to
Library object require 'watir' include Watir
Create a new IE object ie IE.new Go to the
web site ie.goto("http//localhost/Page7.asp")
Check for text on the web page if
(ie.contains_text("Testing Web Applications with
Ruby and Watir")) puts "Text found" end
Interact with the drop down box ie.select_list(na
me, "dropdown").clearSelection ie.select_list(nam
e, "dropdown").select("Beef") ie.select_list(name
, "dropdown").select_value("3")
31
Attaching to another IE Instance
32
Webpage Example 9
ltHtmlgt ltheadgt lttitlegtBoise Code Camp -
Testing with Ruby and Watirlt/titlegt ltscript
type"text/javascript"gt lt!-- function myPopup()
window.open( "http//www.google.com/"
) //--gt lt/scriptgt lt/headgt ltformgt ltinput
type"button" onClick"myPopup()"
value"POP!"gt lt/formgt lt/bodygt lt/htmlgt
33
Watir Test Example 9
Go to the web site ie.goto("http//localhost/
Page9.asp") ie.button( value, "POP!
).click ie2 WatirIE.attach( title, /Google/
) ie2.text_field( name, "q ).set( "Ruby
) ie2.button( name, "btnG ).click ie2.link(
text, "Ruby Programming Language ).click if
(ie2.contains_text( "Ruby is )) puts "Test
Passed Found the Programming Ruby page" end
Close the second instance ie2.close
34
Tables
35
Watir Test Example 11
.. Go to the web site ie.goto(
"http//localhost/Page11.asp ) Click on the
button ie.button( value, "Click Me! ).click
Check that the table is there if ie.table( id,
"booktable ).exists? puts "Test Passed Book
Table found" end Check the tables ie.show_table
s
36
Watir Test Example 11 cont.
ie.tables.each do t t.each do r r.each
do c puts c.text end end end if
ie.tables111 "Book Title" puts "Test
Passed Book Title found in table cell" end if
ie.tables112 "Author" puts "Test
Passed Author found in table cell" end
37
Unit tests
38
Webpage Example 12 cont.
ltHtmlgt ltheadgt lttitlegtBoise Code Camp -
Testing with Ruby and Watirlt/titlegt lt/headgt ltbody
bgcolor"antiquewhite"gt ltimg src"BoiseCodeCamp-
round.gif"gt lth2gtVersion 2.0lt/h2gt ltbrgt lth1gtWelcome
to Boise Code Camp 2007lt/h1gt lth3gtTesting Web
Applications with Ruby and Watirlt/h3gt ltbrgt lta
id"1" name"msnlink" href"http//www.msn.com"gtMS
Nlt/agtltbrgt lta id"2" name"yahoolink"
href"http//www.yahoo.com"gtYahoolt/agtltbrgt lta
id"3" name"slashdotlink" href"http//slashdot.o
rg/"gtSlashdotlt/agtltbrgt lta id"4"
name"elegantcode" href"http//www.elegantcode.co
m/"gtElegant Codelt/agtltbrgt lta id"5"
name"pettichordlink" href"http//www.pettichord.
com/"gtBret Pettichordlt/agtltbrgt ltpgtFill out this
form!lt/pgt ltform action"page3next.asp"
method"post"gt ltpgtEnter Stuff ltInput
type"text" name"searchbox"gtlt/pgt ltpgtCheck
the Box ltInput type"checkbox"
name"checkthebox"gtlt/pgt ltpgtOption 1ltInput
type"radio" name"radiobutton1"gtlt/pgt
ltpgtOption 2ltInput type"radio" name"radiobutton2"
gtlt/pgt ltpgtOption 3ltInput type"radio"
name"radiobutton3"gtlt/pgt ltselect
name"dropdown"gt ltoption value"1"
selected gtChicken ltoption value"2"gtBeef
ltoption value"3"gtVegetarian
lt/selectgt ltpgtltInput type"submit"
value"submit"gtlt/pgt lt/formgt lt/bodygt lt/htmlgt
39
Watir Test Example 12 cont.
require 'watir' include Watir require
'test/unit' class TC_ExampleTestCase lt
TestUnitTestCase def test_1_CheckText
ie.goto( "http//localhost/Page12.asp")
Check for text on the web page assert(
ie.contains_text( "Testing Web Applications with
Ruby and Watir ) ) end def test_2_Links
ie.goto("http//localhost/Page12.asp")
Check for some links assert( ie.link( text,
"Slashdot ).exists? ) assert( ie.link(
text, /Code/ ).exists? ) assert( ie.link(
url, /yahoo/ ).exists? ) assert( ie.link(
id, "1 ).text "MSN ) end def
test_3_ClickLink ie.goto(
"http//localhost/Page12.asp ) Click on a
link ie.link( text, "Slashdot ).click
assert( ie.link(text, "Subscribe ).exists? )
ie.back end end
40
IRB Ruby Interactive Shell
41
(No Transcript)
42
Now go forth and test..
43
Resources
  • www.openqa.org/watir
  • Downloads
  • Installation Instructions
  • Active forum

44
Thank you
Write a Comment
User Comments (0)
About PowerShow.com