49
Automated Web Page Testing with Selenium IDE: A Tutorial Mary Ann May-Pumphrey [email protected] 3/10/09

Mary Ann May-Pumphrey SSQA 03-10-2009

Embed Size (px)

Citation preview

Page 1: Mary Ann May-Pumphrey SSQA 03-10-2009

8/6/2019 Mary Ann May-Pumphrey SSQA 03-10-2009

http://slidepdf.com/reader/full/mary-ann-may-pumphrey-ssqa-03-10-2009 1/49

Automated Web Page Testingwith Selenium IDE: A Tutorial

Mary Ann May-Pumphrey

[email protected]/10/09

Page 2: Mary Ann May-Pumphrey SSQA 03-10-2009

8/6/2019 Mary Ann May-Pumphrey SSQA 03-10-2009

http://slidepdf.com/reader/full/mary-ann-may-pumphrey-ssqa-03-10-2009 2/49

What is Selenium IDE?

• An open-source tool for building automatedtest suites of web pages

• An extension to Firefox

• Named for the antidote for Mercury poisoning

(Mercury Interactive created WinRunner)

Page 3: Mary Ann May-Pumphrey SSQA 03-10-2009

8/6/2019 Mary Ann May-Pumphrey SSQA 03-10-2009

http://slidepdf.com/reader/full/mary-ann-may-pumphrey-ssqa-03-10-2009 3/49

Recommended First Steps forLearning Selenium*

1. Learn how to create tests in Selenium IDE.

2. Learn how to run Selenium IDE (SIDE) testsagainst different browsers/platforms usingSelenium RC (Remote Control) server.

3. Learn how to write Selenium tests in anyone of several supported languages using

Selenium RC drivers.

Page 4: Mary Ann May-Pumphrey SSQA 03-10-2009

8/6/2019 Mary Ann May-Pumphrey SSQA 03-10-2009

http://slidepdf.com/reader/full/mary-ann-may-pumphrey-ssqa-03-10-2009 4/49

SIDE Test Case Structure

• 3-column HTML table

• Calls to the Selenium API (in the first column ofeach row of table)

• JavaScript code

• For script argument to a Selenium command

• In a user-created extension file

• Potentially for any command’s argument via

javascript{code }

Page 5: Mary Ann May-Pumphrey SSQA 03-10-2009

8/6/2019 Mary Ann May-Pumphrey SSQA 03-10-2009

http://slidepdf.com/reader/full/mary-ann-may-pumphrey-ssqa-03-10-2009 5/49

SIDE Test Case Structure

Page 6: Mary Ann May-Pumphrey SSQA 03-10-2009

8/6/2019 Mary Ann May-Pumphrey SSQA 03-10-2009

http://slidepdf.com/reader/full/mary-ann-may-pumphrey-ssqa-03-10-2009 6/49

SIDE Test Suite Structure

• 1-column HTML table

• One link to each test, in the only column ofeach row of table

Page 7: Mary Ann May-Pumphrey SSQA 03-10-2009

8/6/2019 Mary Ann May-Pumphrey SSQA 03-10-2009

http://slidepdf.com/reader/full/mary-ann-may-pumphrey-ssqa-03-10-2009 7/49

SIDE Test Suite Structure

Page 8: Mary Ann May-Pumphrey SSQA 03-10-2009

8/6/2019 Mary Ann May-Pumphrey SSQA 03-10-2009

http://slidepdf.com/reader/full/mary-ann-may-pumphrey-ssqa-03-10-2009 8/49

Skills Needed to Use SIDEEffectively

• HTML

• JavaScript, including DOM (Document Object

Model)

• Regular expressions

• Xpath expressions

Page 9: Mary Ann May-Pumphrey SSQA 03-10-2009

8/6/2019 Mary Ann May-Pumphrey SSQA 03-10-2009

http://slidepdf.com/reader/full/mary-ann-may-pumphrey-ssqa-03-10-2009 9/49

Installation of SIDE

1. Point Firefox at Selenium IDE installationpage on OpenQA web site.

2. Select the download link for 1.0 Beta 2.

3. If nothing happens, then select the Edit

Options button just above the page. Thenselect the Allow button on the AllowedSites pop-up, followed by the Close button.

Page 10: Mary Ann May-Pumphrey SSQA 03-10-2009

8/6/2019 Mary Ann May-Pumphrey SSQA 03-10-2009

http://slidepdf.com/reader/full/mary-ann-may-pumphrey-ssqa-03-10-2009 10/49

Installation of SIDE

4. Select the download link for 1.0 Beta 2again.

5. Select the Install Now button of theSoftware Installation window.

6. Select the Restart Firefox button of theAdd-ons window.

Page 11: Mary Ann May-Pumphrey SSQA 03-10-2009

8/6/2019 Mary Ann May-Pumphrey SSQA 03-10-2009

http://slidepdf.com/reader/full/mary-ann-may-pumphrey-ssqa-03-10-2009 11/49

Bringing Up SIDE

Firefox’s

Tools => Selenium IDE

Page 12: Mary Ann May-Pumphrey SSQA 03-10-2009

8/6/2019 Mary Ann May-Pumphrey SSQA 03-10-2009

http://slidepdf.com/reader/full/mary-ann-may-pumphrey-ssqa-03-10-2009 12/49

Example: Link-Checking

1. Point Firefox browser at SUT, De Anza A-ZDirectory.

2. Click on the red Record button to startrecording if needed (it is already on bydefault when SIDE is first brought up).

3. Click on browser window to give it focus.

Page 13: Mary Ann May-Pumphrey SSQA 03-10-2009

8/6/2019 Mary Ann May-Pumphrey SSQA 03-10-2009

http://slidepdf.com/reader/full/mary-ann-may-pumphrey-ssqa-03-10-2009 13/49

Example: Link-Checking

4. Click on letter T from alphabetical horizontalnavigation bar.

5. Select Technical Writing link, and wait fornew page to load.

6. Select verifyTitle Technical Writing fromcontext menu.

Page 14: Mary Ann May-Pumphrey SSQA 03-10-2009

8/6/2019 Mary Ann May-Pumphrey SSQA 03-10-2009

http://slidepdf.com/reader/full/mary-ann-may-pumphrey-ssqa-03-10-2009 14/49

Example: Link-Checking

Always look here if desiredSelenium command isn’t listed

Page 15: Mary Ann May-Pumphrey SSQA 03-10-2009

8/6/2019 Mary Ann May-Pumphrey SSQA 03-10-2009

http://slidepdf.com/reader/full/mary-ann-may-pumphrey-ssqa-03-10-2009 15/49

Example: Link-Checking

7. Select browser's Back button.

8. Repeat the last three steps for theTranscripts link.

9. Click the red Record button to stoprecording.

Page 16: Mary Ann May-Pumphrey SSQA 03-10-2009

8/6/2019 Mary Ann May-Pumphrey SSQA 03-10-2009

http://slidepdf.com/reader/full/mary-ann-may-pumphrey-ssqa-03-10-2009 16/49

Example: Link-Checking

Captured code

Page 17: Mary Ann May-Pumphrey SSQA 03-10-2009

8/6/2019 Mary Ann May-Pumphrey SSQA 03-10-2009

http://slidepdf.com/reader/full/mary-ann-may-pumphrey-ssqa-03-10-2009 17/49

Example: Link-Checking

• At this point, all of the user actionsexcept the clicks on the Back button

have been recorded.

• To take care of these clicks, add calls

to the goBackAndWait command.

Page 18: Mary Ann May-Pumphrey SSQA 03-10-2009

8/6/2019 Mary Ann May-Pumphrey SSQA 03-10-2009

http://slidepdf.com/reader/full/mary-ann-may-pumphrey-ssqa-03-10-2009 18/49

Inserting SeleneseCommands from Table View

1. Select Table tab of Selenium IDE.

2. Select third click/clickAndWait.

3. Bring up the context menu of IDE and selectInsert New Command.

Page 19: Mary Ann May-Pumphrey SSQA 03-10-2009

8/6/2019 Mary Ann May-Pumphrey SSQA 03-10-2009

http://slidepdf.com/reader/full/mary-ann-may-pumphrey-ssqa-03-10-2009 19/49

Inserting SeleneseCommands from Table View

Arg-1

Arg-2

Contextmenu

Insertionpoint

Page 20: Mary Ann May-Pumphrey SSQA 03-10-2009

8/6/2019 Mary Ann May-Pumphrey SSQA 03-10-2009

http://slidepdf.com/reader/full/mary-ann-may-pumphrey-ssqa-03-10-2009 20/49

Inserting SeleneseCommands from Table View

4. Type "g" into Command field.

5. Select goBackAndWait from commandmenu.

Page 21: Mary Ann May-Pumphrey SSQA 03-10-2009

8/6/2019 Mary Ann May-Pumphrey SSQA 03-10-2009

http://slidepdf.com/reader/full/mary-ann-may-pumphrey-ssqa-03-10-2009 21/49

Inserting SeleneseCommands from Table View

Command

menu

Page 22: Mary Ann May-Pumphrey SSQA 03-10-2009

8/6/2019 Mary Ann May-Pumphrey SSQA 03-10-2009

http://slidepdf.com/reader/full/mary-ann-may-pumphrey-ssqa-03-10-2009 22/49

Replaying a Test

1. Select File=>Save Test Case As to savethe test.

2. Drag the speed slider to Slow.

3. Select the second green right-pointing arrow

(Play from the beginning or start point ).

Page 23: Mary Ann May-Pumphrey SSQA 03-10-2009

8/6/2019 Mary Ann May-Pumphrey SSQA 03-10-2009

http://slidepdf.com/reader/full/mary-ann-may-pumphrey-ssqa-03-10-2009 23/49

Replaying a Test

Playbackglyph

Currentlyexecutingline

Results

Speedslider

Eraselogcontents

Page 24: Mary Ann May-Pumphrey SSQA 03-10-2009

8/6/2019 Mary Ann May-Pumphrey SSQA 03-10-2009

http://slidepdf.com/reader/full/mary-ann-may-pumphrey-ssqa-03-10-2009 24/49

Analyzing the Results

• From Table view, observe the green vs.red shading.

• From Table or Source view, select theLog tab and look for errors (bold red

font).

Page 25: Mary Ann May-Pumphrey SSQA 03-10-2009

8/6/2019 Mary Ann May-Pumphrey SSQA 03-10-2009

http://slidepdf.com/reader/full/mary-ann-may-pumphrey-ssqa-03-10-2009 25/49

Adding Comments from TableView

Bring up the context menu of IDE andselect Insert New Comment.

Page 26: Mary Ann May-Pumphrey SSQA 03-10-2009

8/6/2019 Mary Ann May-Pumphrey SSQA 03-10-2009

http://slidepdf.com/reader/full/mary-ann-may-pumphrey-ssqa-03-10-2009 26/49

Adding Comments from TableView

Comments

Page 27: Mary Ann May-Pumphrey SSQA 03-10-2009

8/6/2019 Mary Ann May-Pumphrey SSQA 03-10-2009

http://slidepdf.com/reader/full/mary-ann-may-pumphrey-ssqa-03-10-2009 27/49

AssertionsPrefixes Sample Suffixes

assert

verify

waitFor

Alert

NotAlert

Confirmation

NotConfirmation

TextPresentTextNotPresent

Title

NotTitle

Page 28: Mary Ann May-Pumphrey SSQA 03-10-2009

8/6/2019 Mary Ann May-Pumphrey SSQA 03-10-2009

http://slidepdf.com/reader/full/mary-ann-may-pumphrey-ssqa-03-10-2009 28/49

Page 29: Mary Ann May-Pumphrey SSQA 03-10-2009

8/6/2019 Mary Ann May-Pumphrey SSQA 03-10-2009

http://slidepdf.com/reader/full/mary-ann-may-pumphrey-ssqa-03-10-2009 29/49

Patterns, Locators, Scripts

Most arguments required by the SeleniumAPI fall into three categories:

Patterns

Locators

Scripts

Page 30: Mary Ann May-Pumphrey SSQA 03-10-2009

8/6/2019 Mary Ann May-Pumphrey SSQA 03-10-2009

http://slidepdf.com/reader/full/mary-ann-may-pumphrey-ssqa-03-10-2009 30/49

Patterns: glob (the default)

glob:pattern 

* (anything/nothing)

? (any single character)

Example: verifyTitle glob:Technical *Writing

More robust test now--it allows additionalcharacters, such as extraneous spaces, to bepresent between the words.

Page 31: Mary Ann May-Pumphrey SSQA 03-10-2009

8/6/2019 Mary Ann May-Pumphrey SSQA 03-10-2009

http://slidepdf.com/reader/full/mary-ann-may-pumphrey-ssqa-03-10-2009 31/49

Page 32: Mary Ann May-Pumphrey SSQA 03-10-2009

8/6/2019 Mary Ann May-Pumphrey SSQA 03-10-2009

http://slidepdf.com/reader/full/mary-ann-may-pumphrey-ssqa-03-10-2009 32/49

Page 33: Mary Ann May-Pumphrey SSQA 03-10-2009

8/6/2019 Mary Ann May-Pumphrey SSQA 03-10-2009

http://slidepdf.com/reader/full/mary-ann-may-pumphrey-ssqa-03-10-2009 33/49

Patterns: exact

exact:string 

Seems a bit pointless!

The default glob: pattern-matching without anyspecial characters does the same thing.

Page 34: Mary Ann May-Pumphrey SSQA 03-10-2009

8/6/2019 Mary Ann May-Pumphrey SSQA 03-10-2009

http://slidepdf.com/reader/full/mary-ann-may-pumphrey-ssqa-03-10-2009 34/49

Locators: identifier=identifier=identifier 

• Specifies first element with matching id attribute ifone exists; otherwise, first element with matching

name attribute.

• Default locator tag if identifier doesn’t start with

document (DOM locator) or // (Xpath).

 /* Enter a stored search string into input field */ 

type all_s ${search_string}

Page 35: Mary Ann May-Pumphrey SSQA 03-10-2009

8/6/2019 Mary Ann May-Pumphrey SSQA 03-10-2009

http://slidepdf.com/reader/full/mary-ann-may-pumphrey-ssqa-03-10-2009 35/49

Locators: id=id=id 

Specifies first element with matching id attribute.

 /* Enter a stored search string into input field */ 

type id=all_s ${search_string}

Page 36: Mary Ann May-Pumphrey SSQA 03-10-2009

8/6/2019 Mary Ann May-Pumphrey SSQA 03-10-2009

http://slidepdf.com/reader/full/mary-ann-may-pumphrey-ssqa-03-10-2009 36/49

Locators: name=name=name 

Specifies first element with matching name attribute.

 /* Enter a stored search string into input field */ 

type name=q ${search_string}

Page 37: Mary Ann May-Pumphrey SSQA 03-10-2009

8/6/2019 Mary Ann May-Pumphrey SSQA 03-10-2009

http://slidepdf.com/reader/full/mary-ann-may-pumphrey-ssqa-03-10-2009 37/49

Locators: dom=dom= javascriptExpression 

document.restOfJavascriptExpression 

 /* Choose item from drop-down with specified label */ 

select

document.schsearch.Uniq_Course_IDComputer Information Systems (CIS)

Page 38: Mary Ann May-Pumphrey SSQA 03-10-2009

8/6/2019 Mary Ann May-Pumphrey SSQA 03-10-2009

http://slidepdf.com/reader/full/mary-ann-may-pumphrey-ssqa-03-10-2009 38/49

Locators: xpath=xpath=xpathExpression 

 // restOfXpathExpression 

 /* Select checkbox with value attribute of “Tu” */ 

click //input[@value='Tu']

 /* Select checkbox with id attribute containing “Thu” */ 

click //input[contains(@id,'Thu')]

Page 39: Mary Ann May-Pumphrey SSQA 03-10-2009

8/6/2019 Mary Ann May-Pumphrey SSQA 03-10-2009

http://slidepdf.com/reader/full/mary-ann-may-pumphrey-ssqa-03-10-2009 39/49

Page 40: Mary Ann May-Pumphrey SSQA 03-10-2009

8/6/2019 Mary Ann May-Pumphrey SSQA 03-10-2009

http://slidepdf.com/reader/full/mary-ann-may-pumphrey-ssqa-03-10-2009 40/49

Locators: link=link=textPattern 

Note that the argument is a textPattern, not atextString!

 /* “Assessment and Placement Information” link */ 

click

link=regexp:Assessment +.* +Placement +Information

Page 41: Mary Ann May-Pumphrey SSQA 03-10-2009

8/6/2019 Mary Ann May-Pumphrey SSQA 03-10-2009

http://slidepdf.com/reader/full/mary-ann-may-pumphrey-ssqa-03-10-2009 41/49

ScriptsstoreEval

(

script,

variableName 

)

storeEval

this.browserbot.bodyText().match(/ of about +([0-9]+)\./)[1]

hits

storeExpression

(expression,

variableName 

)

storeExpression

javascript{this.browserbot.bodyText().match(/of about +([0-9]+)\./)[1]}

hits

Page 42: Mary Ann May-Pumphrey SSQA 03-10-2009

8/6/2019 Mary Ann May-Pumphrey SSQA 03-10-2009

http://slidepdf.com/reader/full/mary-ann-may-pumphrey-ssqa-03-10-2009 42/49

Extensions to SIDEWrite your own or

download one such asgoto_sel_ide.js whichprovides loops and

conditionals.

Specify via

Options=>Optionswindow

Page 43: Mary Ann May-Pumphrey SSQA 03-10-2009

8/6/2019 Mary Ann May-Pumphrey SSQA 03-10-2009

http://slidepdf.com/reader/full/mary-ann-may-pumphrey-ssqa-03-10-2009 43/49

SIDE Gotchas/Shortcomings• Log file cannot be saved other than via copy/paste.

• User clicks on links are sometimes recorded asclick rather than clickAndWait.

• Test suite functionality is minimal.

• No built-in subroutines, loops, or conditionals.

• Xpath implementation seems buggy.

Page 44: Mary Ann May-Pumphrey SSQA 03-10-2009

8/6/2019 Mary Ann May-Pumphrey SSQA 03-10-2009

http://slidepdf.com/reader/full/mary-ann-may-pumphrey-ssqa-03-10-2009 44/49

Execution on Other Platforms1. Download the Selenium RC server.

2.   java -jar selenium-server.jar -htmlSuite

browserString startURL suiteFile resultFile 

Example:

 java -jar selenium-server.jar -htmlSuite "*chrome"http://www.ebay.com

~/Desktop/De*/SIDE-S2008/testsuite/testsuite.html

 /tmp/results.html

Page 45: Mary Ann May-Pumphrey SSQA 03-10-2009

8/6/2019 Mary Ann May-Pumphrey SSQA 03-10-2009

http://slidepdf.com/reader/full/mary-ann-may-pumphrey-ssqa-03-10-2009 45/49

Demo: Checking All De AnzaA-Z Links

Page 46: Mary Ann May-Pumphrey SSQA 03-10-2009

8/6/2019 Mary Ann May-Pumphrey SSQA 03-10-2009

http://slidepdf.com/reader/full/mary-ann-may-pumphrey-ssqa-03-10-2009 46/49

Demo: Checking All De AnzaA-Z Links

JavaScript extension file (the golden file):

var a_z = new Array();

 // One pair/link: link-text followed by landing page titlea_z.push("About De Anza","About De Anza");

a_z.push("Calendar","Academic Calendar/Final Exam Schedule");

a_z.push("Academic Freedom Policy","Academic Freedom");.

.

.

a_z.push("Astronomy Department","regexp:D e A n z a C o l l e g

e Physical Sciences, Math., & Engineering Division(PSME).*http://nebula.deanza.edu");

Page 47: Mary Ann May-Pumphrey SSQA 03-10-2009

8/6/2019 Mary Ann May-Pumphrey SSQA 03-10-2009

http://slidepdf.com/reader/full/mary-ann-may-pumphrey-ssqa-03-10-2009 47/49

Demo: Checking All De AnzaA-Z Links

Test case:

Requires

extension

Page 48: Mary Ann May-Pumphrey SSQA 03-10-2009

8/6/2019 Mary Ann May-Pumphrey SSQA 03-10-2009

http://slidepdf.com/reader/full/mary-ann-may-pumphrey-ssqa-03-10-2009 48/49

In-Depth SIDE Courses

• De Anza College CIS-140: Automated Web Page Testing with Selenium IDE 

• Santa Clara Adult Education’s High TechAcademy: Software Test Automation using 

Selenium IDE 

• Portnov QA School

Page 49: Mary Ann May-Pumphrey SSQA 03-10-2009

8/6/2019 Mary Ann May-Pumphrey SSQA 03-10-2009

http://slidepdf.com/reader/full/mary-ann-may-pumphrey-ssqa-03-10-2009 49/49

Questions? Want a copy ofthese slides?

[email protected]