web application testing with selenium for dyndns.com
DESCRIPTION
Cory von Wallenstein walks through some best practices for using Selenium to test a large web site like DynDNS.comTRANSCRIPT
![Page 1: Web Application Testing with Selenium for DynDNS.com](https://reader033.vdocuments.pub/reader033/viewer/2022042816/5589b31fd8b42a7d258b4711/html5/thumbnails/1.jpg)
SeleniumSeminar
CoryvonWallenstein
February12,2009
![Page 2: Web Application Testing with Selenium for DynDNS.com](https://reader033.vdocuments.pub/reader033/viewer/2022042816/5589b31fd8b42a7d258b4711/html5/thumbnails/2.jpg)
Overview
• WhatisSelenium?Whatisitnot?
• Seleniumasasupportandbug‐reporttool
• High‐levelbestpracCces• UnderthehoodofourimplementaCon
![Page 3: Web Application Testing with Selenium for DynDNS.com](https://reader033.vdocuments.pub/reader033/viewer/2022042816/5589b31fd8b42a7d258b4711/html5/thumbnails/3.jpg)
UnigressificaConalTesCng
• TermsIuse,exactdefiniConsdebatable
• UnittesCng– “TestonethinginisolaCon”
• RegressiontesCng– “Testonethingthatbroke”
• FuncConaltesCng– “Testthingsworkingtogether”
• VerificaContesCng– “Testallofthethingsworkingtogether”
![Page 4: Web Application Testing with Selenium for DynDNS.com](https://reader033.vdocuments.pub/reader033/viewer/2022042816/5589b31fd8b42a7d258b4711/html5/thumbnails/4.jpg)
What’stheproblem?Iwantto…
• Testthecode• Testthatthecodeproducesawebpage• Testthecontentonthewebpage• TestthesemanCcmeaningofthecontentonthewebpage
• Testthedisplayoftheformthatisbelowthecontentonthewebpage
• Testthedisplayoftheformthatisabovethecontentonthewebpage
![Page 5: Web Application Testing with Selenium for DynDNS.com](https://reader033.vdocuments.pub/reader033/viewer/2022042816/5589b31fd8b42a7d258b4711/html5/thumbnails/5.jpg)
What’stheproblem?Iwantto…
• Testthesubmissionoftheformwithinvaliddatasuchthatanerrorisdisplayedabovetheform(serversidevalidaCon)andtheformisabovethecontentonthewebpage.
• TestthesubmissionoftheformwithinvaliddatasuchthatanerrorisdisplayedabovetheformwithclientsidevalidaConiftheclienthasJavaScriptandserversidevalidaConifnotandtheformisabovethecontentonthewebpage.
![Page 6: Web Application Testing with Selenium for DynDNS.com](https://reader033.vdocuments.pub/reader033/viewer/2022042816/5589b31fd8b42a7d258b4711/html5/thumbnails/6.jpg)
What’stheproblem?Iwantto…
• TestthesubmissionoftheformwithinvaliddatasuchthatanerrorisdisplayedabovetheformwithclientsidevalidaConiftheclienthasJavaScriptandserversidevalidaConifnotandtheformisabovethecontentonthewebpage,exceptforIE6,wheretheformerrordisplaysbelowtheform.
![Page 7: Web Application Testing with Selenium for DynDNS.com](https://reader033.vdocuments.pub/reader033/viewer/2022042816/5589b31fd8b42a7d258b4711/html5/thumbnails/7.jpg)
What’stheproblem?Iwantto…
• TestthesubmissionoftheformwithinvaliddatasuchthatanerrorisdisplayedabovetheformwithclientsidevalidaConiftheclienthasJavaScriptandserversidevalidaConifnotandtheformisabovethecontentonthewebpage,exceptforIE6,wheretheformerrordisplaysbelowtheform.forFirefox,Safari,Opera,andIE7,butdisplayamessageforIE6userstellingthemtoswitchbrowsers.
![Page 8: Web Application Testing with Selenium for DynDNS.com](https://reader033.vdocuments.pub/reader033/viewer/2022042816/5589b31fd8b42a7d258b4711/html5/thumbnails/8.jpg)
What’stheproblem?Iwantto…
• TestthesubmissionoftheformwithinvaliddatasuchthatanerrorisdisplayedabovetheformwithclientsidevalidaConiftheclienthasJavaScriptandserversidevalidaConifnotandtheformisabovethecontentonthewebpage,exceptforIE6,wheretheformerrordisplaysbelowtheform.forFirefox,Safari,Opera,andIE7,butdisplayamessageforIE6userstellingthemtoswitchbrowsersandmakesure*nixusersgetavirtualhigh‐fivewhentheysubmittheform.
![Page 9: Web Application Testing with Selenium for DynDNS.com](https://reader033.vdocuments.pub/reader033/viewer/2022042816/5589b31fd8b42a7d258b4711/html5/thumbnails/9.jpg)
What’stheproblem?Iwantto…
• MakesureitallsCllworkssixmonthsfromnowwhenIforgetwhattheheckthisformwassupposedtodo.
![Page 10: Web Application Testing with Selenium for DynDNS.com](https://reader033.vdocuments.pub/reader033/viewer/2022042816/5589b31fd8b42a7d258b4711/html5/thumbnails/10.jpg)
TakealookatSelenium.
h'p://seleniumhq.org
![Page 11: Web Application Testing with Selenium for DynDNS.com](https://reader033.vdocuments.pub/reader033/viewer/2022042816/5589b31fd8b42a7d258b4711/html5/thumbnails/11.jpg)
Whatisitnot?
![Page 12: Web Application Testing with Selenium for DynDNS.com](https://reader033.vdocuments.pub/reader033/viewer/2022042816/5589b31fd8b42a7d258b4711/html5/thumbnails/12.jpg)
SeleniumArchitecture
• Recordworkflows• Interactwithcontentdisplayedinthebrowserinafairlyrobustway
• Createtestsfromworkflowsinthelanguageofyourchoice
• SametestcodecanbebrowserandOSagnosCc
• Built‐inremotecontrolandgridfuncConality
![Page 13: Web Application Testing with Selenium for DynDNS.com](https://reader033.vdocuments.pub/reader033/viewer/2022042816/5589b31fd8b42a7d258b4711/html5/thumbnails/13.jpg)
![Page 14: Web Application Testing with Selenium for DynDNS.com](https://reader033.vdocuments.pub/reader033/viewer/2022042816/5589b31fd8b42a7d258b4711/html5/thumbnails/14.jpg)
![Page 15: Web Application Testing with Selenium for DynDNS.com](https://reader033.vdocuments.pub/reader033/viewer/2022042816/5589b31fd8b42a7d258b4711/html5/thumbnails/15.jpg)
SeleniumIDE
• FirefoxPlugin• Recordworkflows• Playbackworkflows• Exchangeworkflows• AgoodstarCngpointfortestcode
![Page 16: Web Application Testing with Selenium for DynDNS.com](https://reader033.vdocuments.pub/reader033/viewer/2022042816/5589b31fd8b42a7d258b4711/html5/thumbnails/16.jpg)
BestPracCces
![Page 17: Web Application Testing with Selenium for DynDNS.com](https://reader033.vdocuments.pub/reader033/viewer/2022042816/5589b31fd8b42a7d258b4711/html5/thumbnails/17.jpg)
High‐levelBestPracCces
• TheIDEgeneratedcodeisgarbage,butyoufullyexpectedthat.:‐)
• Verydependentonscreenscraping• VerydependentonelementnesCng
• SuscepCbletoCmingissues
• Butit’sagoodstarCngpointforlearning!• (BrushuponyourXpath)
![Page 18: Web Application Testing with Selenium for DynDNS.com](https://reader033.vdocuments.pub/reader033/viewer/2022042816/5589b31fd8b42a7d258b4711/html5/thumbnails/18.jpg)
GoalsforSeleniumTesCng
• Ifstuffmovesaround,butthefuncConalityisthere,thetestshouldnotbreaknorrequiremodificaCon.
• Ifcontentischanged,butthefuncConalityisthere,thetestshouldnotbreaknorrequiremodificaCon.
• Ifyournetworkislatentoryourcomputerisunderload,thetestshouldnotbreak.
![Page 19: Web Application Testing with Selenium for DynDNS.com](https://reader033.vdocuments.pub/reader033/viewer/2022042816/5589b31fd8b42a7d258b4711/html5/thumbnails/19.jpg)
UseSpecificDOMIDs
• Trouble://div[@id='sidenav‐content']/table[1].0.2
• Lesstrouble://div[@id=’bu;on_next’]
• Designfortest• IDisunlikelytochange(ifyouhaveagoodnamingscheme!)
• Moveitemtotestanywhereonpage;acrosspages
• Easytoseparate“isitthere?”from“doesitcontainwhatIexpectitto?”
![Page 20: Web Application Testing with Selenium for DynDNS.com](https://reader033.vdocuments.pub/reader033/viewer/2022042816/5589b31fd8b42a7d258b4711/html5/thumbnails/20.jpg)
AvoidStringMatching
• Troubleinscrapingscreenforstring:Anerroroccurred.Sorry.Toughnoogies.
• Lesstroubleincheckingpresenceofelement://label[@for='username'and@class='error']
• UsetheDOMagributesasmuchaspossible.
• Matchlongstringsasligleaspossible.
• Bestkepttokeywords…doeselementcontain:– “required”,“orderfailed”,”error”
![Page 21: Web Application Testing with Selenium for DynDNS.com](https://reader033.vdocuments.pub/reader033/viewer/2022042816/5589b31fd8b42a7d258b4711/html5/thumbnails/21.jpg)
IsThePageReadyToTest?
• Built‐in“ispagedoneloading”methodlessthanperfect.
• Lookforsomethingonthepage– Header– Footer– Ajax–Noswirlyicon
![Page 22: Web Application Testing with Selenium for DynDNS.com](https://reader033.vdocuments.pub/reader033/viewer/2022042816/5589b31fd8b42a7d258b4711/html5/thumbnails/22.jpg)
GoHigherLevel
• Startrefactoringintohigherlevelmethodssoonerratherthanlater
• Commonones:– isPageReallyReady– clickAndWait
– createNewAccount– login– assertBlahAndCaptureScreenshot– populateFormAndAssertDataAppearsInDatabase
![Page 23: Web Application Testing with Selenium for DynDNS.com](https://reader033.vdocuments.pub/reader033/viewer/2022042816/5589b31fd8b42a7d258b4711/html5/thumbnails/23.jpg)
GoHigherLevel
• Organizebaseclassesaroundworkflows– Why?Commontestfixtures!
• Commonfixtures:– Testsrequiringanaccount– Testsrequiringnoaccount– Testsrequiringsigningupforanaccount– Testsrequiringapaidforitem
– Testsrequiringdatatodisplaythatisdifficulttoproduce
![Page 24: Web Application Testing with Selenium for DynDNS.com](https://reader033.vdocuments.pub/reader033/viewer/2022042816/5589b31fd8b42a7d258b4711/html5/thumbnails/24.jpg)
MakeChangesEasy
• Organizeunittestclasses/filesaroundURIs• EdgecasetesCng• DatavalidaCon• Loggedinversusloggedout
![Page 25: Web Application Testing with Selenium for DynDNS.com](https://reader033.vdocuments.pub/reader033/viewer/2022042816/5589b31fd8b42a7d258b4711/html5/thumbnails/25.jpg)
MakeChangesEasy
• OrganizefuncConaltestclassesaroundworkflows• Createanaccount(mulCplesteps)
• Buysomething
• RMA/cancelsomething
• Provisionsomething
• Thing1interactswithThing2
![Page 26: Web Application Testing with Selenium for DynDNS.com](https://reader033.vdocuments.pub/reader033/viewer/2022042816/5589b31fd8b42a7d258b4711/html5/thumbnails/26.jpg)
PlanforFailure
• Keepunit,regression,funcConal,andverificaContestsseparate
• IdealisfuncConaltestfailed,andaunittesttoldyouexactlywhatcausedthefailure
• OrafuncConaltestfailed,andaregressiontesttoldyouyou’veseenthisbugbefore
• Nodebuggingnecessary
![Page 27: Web Application Testing with Selenium for DynDNS.com](https://reader033.vdocuments.pub/reader033/viewer/2022042816/5589b31fd8b42a7d258b4711/html5/thumbnails/27.jpg)
PlanforFailure
• Keepunit,regression,funcConal,andverificaContestsseparate
• ShortenCmebetweenfailurecreaConandfailurediscovery.
• Runtestsuitesatdifferentfrequencies/events.
![Page 28: Web Application Testing with Selenium for DynDNS.com](https://reader033.vdocuments.pub/reader033/viewer/2022042816/5589b31fd8b42a7d258b4711/html5/thumbnails/28.jpg)
AvoidWorkflowOverlap
• Doasmuchsetupbehindthescenesaspossible– Createanaccountinthedatabaseratherthanform– Addanorderiteminthedatabase…
– Etc.• Aimtotestjustasingle“thing”pertestcase
• Refactorprerequisiteworkflowstobaseclasses
![Page 29: Web Application Testing with Selenium for DynDNS.com](https://reader033.vdocuments.pub/reader033/viewer/2022042816/5589b31fd8b42a7d258b4711/html5/thumbnails/29.jpg)
SeleniumisSlow
• Raretohaveatestcaseexecuteinlessthan5‐10seconds.
• Cleanbrowserforeachtestcase.IsolaCon.– HumanCmemorevaluablethanmachineCme.
• Planaccordingly.• Openexasperatedbyexternaldependenciesandsystems…
![Page 30: Web Application Testing with Selenium for DynDNS.com](https://reader033.vdocuments.pub/reader033/viewer/2022042816/5589b31fd8b42a7d258b4711/html5/thumbnails/30.jpg)
Mockup!Unplug!
• EverythingbutaverificaContestshouldusemocking
• Mocking– Mockbehaviorofexternalsysteminafastandreproducibleway
– Example:DynDNS.comandcreditcardprocessor– Beabletoreproducespecificerrorresponses!!!– Anyonecanmakesomethingthatworksonsuccess.OurjobistomakeitworkonparCalfailure.