Upload
matun123
View
223
Download
0
Embed Size (px)
Citation preview
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
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)
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.
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 }
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
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
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
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
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.
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.
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
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.
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.
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
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.
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
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.
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.
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
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.
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
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 ).
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
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).
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.
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
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
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
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
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.
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
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
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.
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}
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}
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}
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)
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')]
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
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
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
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
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.
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
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
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");
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
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
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?