introduction to watir

24
Introduction to Web Introduction to Web Application Testing in Application Testing in Ruby (WATiR) Ruby (WATiR) Presented by Justin Long Presented by Justin Long

Upload: api-3830222

Post on 14-Nov-2014

57 views

Category:

Documents


2 download

DESCRIPTION

PPT on basic WATiR

TRANSCRIPT

Page 1: Introduction to WATIR

Introduction to Web Application Introduction to Web Application Testing in Ruby (WATiR)Testing in Ruby (WATiR)

Presented by Justin LongPresented by Justin Long

Page 2: Introduction to WATIR

My IntroductionMy IntroductionFor those of you that may not know meFor those of you that may not know me• I’m currently a software architect for I’m currently a software architect for

Teleperformance USATeleperformance USA• I was recently a developer for 1-800 Contacts I was recently a developer for 1-800 Contacts

that focuses primarily on their web sitethat focuses primarily on their web site• I’m part of the leadership of the Utah .Net I’m part of the leadership of the Utah .Net

Users Group.Users Group.• I was born on Mac OS, raised by open source I was born on Mac OS, raised by open source

and adopted by Microsoft. and adopted by Microsoft.

Page 3: Introduction to WATIR

Slides and Demo codeSlides and Demo code

• My slides and demo code will be available My slides and demo code will be available online at: online at: http://www.dukk.org/downloads.aspx http://www.dukk.org/downloads.aspx so don’t worry if you miss any linksso don’t worry if you miss any links

Page 4: Introduction to WATIR

What is WATiR?What is WATiR?

• WWeb eb AApplication pplication TTesting esting IIn n RRubyuby

• It is library for the Ruby scripting language It is library for the Ruby scripting language used to automate Internet Explorerused to automate Internet Explorer

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

Page 5: Introduction to WATIR

Setting up WATiRSetting up WATiR• Download the Ruby and WATiR one-click Download the Ruby and WATiR one-click

installers from: http://wtr.rubyforge.org/installers from: http://wtr.rubyforge.org/

• Steps:Steps:1.1. Install Ruby (I’ll be using version: 1.8.6-25)Install Ruby (I’ll be using version: 1.8.6-25)2.2. Install WATiR (I’ll be using version: 1.4.1)Install WATiR (I’ll be using version: 1.4.1)

You can alternatively install WATiR though GEM by You can alternatively install WATiR though GEM by typing “typing “gem install watirgem install watir”” at a command at a command line after Ruby has been installedline after Ruby has been installed

Page 6: Introduction to WATIR

Learning WATiRLearning WATiR

I will only be chipping away at the surface in this I will only be chipping away at the surface in this presentation. I would highly recommend presentation. I would highly recommend checking out the documentation section checking out the documentation section online at http://wtr.rubyforge.org/online at http://wtr.rubyforge.org/

And for those of you that are new to Ruby the And for those of you that are new to Ruby the best place to learn is probably at best place to learn is probably at http://www.ruby-doc.org/http://www.ruby-doc.org/

Page 7: Introduction to WATIR

Development Environments (IDE’s) Development Environments (IDE’s) for Rubyfor Ruby

• I would recommend using one of the many Ruby IDE’s I would recommend using one of the many Ruby IDE’s for your WATiR scripts. Here’s a list of some of your for your WATiR scripts. Here’s a list of some of your selection:selection:

– ScITEScITE (Free) (Free)• In the Ruby Windows installerIn the Ruby Windows installer

– Komodo IDE Komodo IDE ($295) / ($295) / Komodo Edit Komodo Edit (Free)(Free)• http://www.activestate.com/http://www.activestate.com/

– Ruby In Steel Ruby In Steel (Free - $199) (Add-on to VS.Net 2k5)(Free - $199) (Add-on to VS.Net 2k5)• http://www.sapphiresteel.com/http://www.sapphiresteel.com/

Page 8: Introduction to WATIR

Using WATiRUsing WATiR• Using the WATiR API is very easy. Just reference the Using the WATiR API is very easy. Just reference the

WATiR API using the “require” keyword and start WATiR API using the “require” keyword and start codingcoding

require ‘watir’require ‘watir’include Watirinclude Watir

ie = ie = IE.start(“http://www.dukk.org/”)IE.start(“http://www.dukk.org/”)

……

Page 9: Introduction to WATIR

The Watir::IE ClassThe Watir::IE Class

• This is the heart and sole of WATiR (from the This is the heart and sole of WATiR (from the users point of view)users point of view)

• Contains all the methods needed to create, Contains all the methods needed to create, navigate and “probe” the IE browser windownavigate and “probe” the IE browser window

Page 10: Introduction to WATIR

Demo: Quick lap around my siteDemo: Quick lap around my site

Page 11: Introduction to WATIR

Using Ruby’s Interactive Command Using Ruby’s Interactive Command Interpreter (IRB)Interpreter (IRB)

Use it to:Use it to:• Attach to IE windows and quickly identify browser Attach to IE windows and quickly identify browser

objectsobjects• Run quick experiments to see if things will work in your Run quick experiments to see if things will work in your

teststests

• irb(main):001:0> require ‘watir’irb(main):001:0> require ‘watir’• irb(main):002:0> ie = irb(main):002:0> ie = Watir::IE.attach(:title, “My Page")Watir::IE.attach(:title, “My Page")

• irb(main):003:0> ie.show_all_objectsirb(main):003:0> ie.show_all_objects

Page 12: Introduction to WATIR

Demo: Using IRBDemo: Using IRB

• Run IRB from a command line by typing “Run IRB from a command line by typing “irbirb””

Page 13: Introduction to WATIR

Using The Ruby Unit Testing APIUsing The Ruby Unit Testing API• Create a class that extends Test::Unit::TestCaseCreate a class that extends Test::Unit::TestCase• Defined test methods by prefixing them with Defined test methods by prefixing them with

“test”“test”• Setup your assertionsSetup your assertionsclass MyTest < Test::Unit::TestCase

def test_MyPageTest_01assert(true, “Always Passes”)

enddef test_MyPageTest_02

assert(false, “Always Fails”)end

end

Page 14: Introduction to WATIR

TestCase Startup & TeardownTestCase Startup & Teardown• Use the startup method to get you to the page you want to test Use the startup method to get you to the page you want to test

when state matterswhen state matters• Use the teardown method to clean up, close IE, etc…Use the teardown method to clean up, close IE, etc…

def setup()def setup()@ie = Watir::IE.start(“http://myapp.com/”)@ie = Watir::IE.start(“http://myapp.com/”)@ie.link(:text, “Login”).click()@ie.link(:text, “Login”).click()

endenddef teardown()def teardown()

@ie.close()@ie.close()endend

Page 15: Introduction to WATIR

Application DataApplication Data

• I do not recommend trying to manage the I do not recommend trying to manage the state of your applications data using the state of your applications data using the startup and teardown methods if it can be startup and teardown methods if it can be avoided!avoided!

• Use a test data source when ever possible that Use a test data source when ever possible that will allow you to simply rollback all the data at will allow you to simply rollback all the data at onceonce

Page 16: Introduction to WATIR

Demo: Testing my site using the Demo: Testing my site using the Unit Test APIUnit Test API

Page 17: Introduction to WATIR

Introducing FireWATiRIntroducing FireWATiR• FireWATiR is a spin off of the WATiR project that uses FireWATiR is a spin off of the WATiR project that uses

Firefox instead of IEFirefox instead of IE

• Should Should eventuallyeventually work with minimal code changes work with minimal code changes from normal WATiR scriptsfrom normal WATiR scripts

Should Should eventuallyeventually be platform independent as long be platform independent as long as Firefox works in that platform (Though it may not as Firefox works in that platform (Though it may not be supported or documented)be supported or documented)

Page 18: Introduction to WATIR

Current limitations of FireWATiRCurrent limitations of FireWATiR• Object collections are missingObject collections are missing– No links, buttons, text_fields, etc…No links, buttons, text_fields, etc…

• It currently uses the windows registry to know It currently uses the windows registry to know how to launch Firefox so running it on other how to launch Firefox so running it on other platforms will be difficultplatforms will be difficult

Hopefully this stuff will be fixed in the near Hopefully this stuff will be fixed in the near future.future.

Page 19: Introduction to WATIR

Setting up FireWATiRSetting up FireWATiR• Download the gem and JSSh XPI from: Download the gem and JSSh XPI from:

http://code.google.com/p/firewatir/http://code.google.com/p/firewatir/

• Install JSSh XPI (add-in) for Firefox Install JSSh XPI (add-in) for Firefox – This is how FireWATiR talks to FirefoxThis is how FireWATiR talks to Firefox

• Install the FireWATiR gemInstall the FireWATiR gem– This gem isn’t on rubyforge.org so run the gem This gem isn’t on rubyforge.org so run the gem

command from the same directory as the .gem file command from the same directory as the .gem file you downloadedyou downloaded

Page 20: Introduction to WATIR

Using FireWATiRUsing FireWATiR

• Basically the same as WATiR only IE becomes Basically the same as WATiR only IE becomes FirefoxFirefox

require ‘firewatir’require ‘firewatir’

include FireWatirinclude FireWatir

ff = ff = Firefox.start(“http://www.dukk.org/”)Firefox.start(“http://www.dukk.org/”)

……

Page 21: Introduction to WATIR

Demo: Quick Demo of FireWATiRDemo: Quick Demo of FireWATiR

Page 22: Introduction to WATIR

Questions / Comments?Questions / Comments?

Page 23: Introduction to WATIR

Contact InformationContact Information

• Feel free to contact me if you have questions, Feel free to contact me if you have questions, comments or suggestionscomments or suggestions

– Web: Web: http://www.dukk.org/http://www.dukk.org/

– Email: [email protected]: [email protected]

Page 24: Introduction to WATIR

Thanks to our SponsorsThanks to our Sponsors