30
Selenium Seminar Cory von Wallenstein February 12, 2009

Web Application Testing with Selenium for DynDNS.com

  • Upload
    dyn

  • View
    3.019

  • Download
    3

Embed Size (px)

DESCRIPTION

Cory von Wallenstein walks through some best practices for using Selenium to test a large web site like DynDNS.com

Citation preview

Page 1: Web Application Testing with Selenium for DynDNS.com

SeleniumSeminar

CoryvonWallenstein

February12,2009

Page 2: Web Application Testing with Selenium for DynDNS.com

Overview

•  WhatisSelenium?Whatisitnot?

•  Seleniumasasupportandbug‐reporttool

•  High‐levelbestpracCces•  UnderthehoodofourimplementaCon

Page 3: Web Application Testing with Selenium for DynDNS.com

UnigressificaConalTesCng

•  TermsIuse,exactdefiniConsdebatable

•  UnittesCng– “TestonethinginisolaCon”

•  RegressiontesCng– “Testonethingthatbroke”

•  FuncConaltesCng– “Testthingsworkingtogether”

•  VerificaContesCng– “Testallofthethingsworkingtogether”

Page 4: Web Application Testing with Selenium for DynDNS.com

What’stheproblem?Iwantto…

•  Testthecode•  Testthatthecodeproducesawebpage•  Testthecontentonthewebpage•  TestthesemanCcmeaningofthecontentonthewebpage

•  Testthedisplayoftheformthatisbelowthecontentonthewebpage

•  Testthedisplayoftheformthatisabovethecontentonthewebpage

Page 5: Web Application Testing with Selenium for DynDNS.com

What’stheproblem?Iwantto…

•  Testthesubmissionoftheformwithinvaliddatasuchthatanerrorisdisplayedabovetheform(serversidevalidaCon)andtheformisabovethecontentonthewebpage.

•  TestthesubmissionoftheformwithinvaliddatasuchthatanerrorisdisplayedabovetheformwithclientsidevalidaConiftheclienthasJavaScriptandserversidevalidaConifnotandtheformisabovethecontentonthewebpage.

Page 6: Web Application Testing with Selenium for DynDNS.com

What’stheproblem?Iwantto…

•  TestthesubmissionoftheformwithinvaliddatasuchthatanerrorisdisplayedabovetheformwithclientsidevalidaConiftheclienthasJavaScriptandserversidevalidaConifnotandtheformisabovethecontentonthewebpage,exceptforIE6,wheretheformerrordisplaysbelowtheform.

Page 7: Web Application Testing with Selenium for DynDNS.com

What’stheproblem?Iwantto…

•  TestthesubmissionoftheformwithinvaliddatasuchthatanerrorisdisplayedabovetheformwithclientsidevalidaConiftheclienthasJavaScriptandserversidevalidaConifnotandtheformisabovethecontentonthewebpage,exceptforIE6,wheretheformerrordisplaysbelowtheform.forFirefox,Safari,Opera,andIE7,butdisplayamessageforIE6userstellingthemtoswitchbrowsers.

Page 8: Web Application Testing with Selenium for DynDNS.com

What’stheproblem?Iwantto…

•  TestthesubmissionoftheformwithinvaliddatasuchthatanerrorisdisplayedabovetheformwithclientsidevalidaConiftheclienthasJavaScriptandserversidevalidaConifnotandtheformisabovethecontentonthewebpage,exceptforIE6,wheretheformerrordisplaysbelowtheform.forFirefox,Safari,Opera,andIE7,butdisplayamessageforIE6userstellingthemtoswitchbrowsersandmakesure*nixusersgetavirtualhigh‐fivewhentheysubmittheform.

Page 9: Web Application Testing with Selenium for DynDNS.com

What’stheproblem?Iwantto…

•  MakesureitallsCllworkssixmonthsfromnowwhenIforgetwhattheheckthisformwassupposedtodo.

Page 10: Web Application Testing with Selenium for DynDNS.com

TakealookatSelenium.

h'p://seleniumhq.org

Page 11: Web Application Testing with Selenium for DynDNS.com

Whatisitnot?

Page 12: Web Application Testing with Selenium for DynDNS.com

SeleniumArchitecture

•  Recordworkflows•  Interactwithcontentdisplayedinthebrowserinafairlyrobustway

•  Createtestsfromworkflowsinthelanguageofyourchoice

•  SametestcodecanbebrowserandOSagnosCc

•  Built‐inremotecontrolandgridfuncConality

Page 13: Web Application Testing with Selenium for DynDNS.com
Page 14: Web Application Testing with Selenium for DynDNS.com
Page 15: Web Application Testing with Selenium for DynDNS.com

SeleniumIDE

•  FirefoxPlugin•  Recordworkflows•  Playbackworkflows•  Exchangeworkflows•  AgoodstarCngpointfortestcode

Page 16: Web Application Testing with Selenium for DynDNS.com

BestPracCces

Page 17: Web Application Testing with Selenium for DynDNS.com

High‐levelBestPracCces

•  TheIDEgeneratedcodeisgarbage,butyoufullyexpectedthat.:‐)

•  Verydependentonscreenscraping•  VerydependentonelementnesCng

•  SuscepCbletoCmingissues

•  Butit’sagoodstarCngpointforlearning!•  (BrushuponyourXpath)

Page 18: Web Application Testing with Selenium for DynDNS.com

GoalsforSeleniumTesCng

•  Ifstuffmovesaround,butthefuncConalityisthere,thetestshouldnotbreaknorrequiremodificaCon.

•  Ifcontentischanged,butthefuncConalityisthere,thetestshouldnotbreaknorrequiremodificaCon.

•  Ifyournetworkislatentoryourcomputerisunderload,thetestshouldnotbreak.

Page 19: Web Application Testing with Selenium for DynDNS.com

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

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

IsThePageReadyToTest?

•  Built‐in“ispagedoneloading”methodlessthanperfect.

•  Lookforsomethingonthepage–  Header–  Footer–  Ajax–Noswirlyicon

Page 22: Web Application Testing with Selenium for DynDNS.com

GoHigherLevel

•  Startrefactoringintohigherlevelmethodssoonerratherthanlater

•  Commonones:–  isPageReallyReady–  clickAndWait

–  createNewAccount–  login–  assertBlahAndCaptureScreenshot–  populateFormAndAssertDataAppearsInDatabase

Page 23: Web Application Testing with Selenium for DynDNS.com

GoHigherLevel

•  Organizebaseclassesaroundworkflows– Why?Commontestfixtures!

•  Commonfixtures:– Testsrequiringanaccount– Testsrequiringnoaccount– Testsrequiringsigningupforanaccount– Testsrequiringapaidforitem

– Testsrequiringdatatodisplaythatisdifficulttoproduce

Page 24: Web Application Testing with Selenium for DynDNS.com

MakeChangesEasy

•  Organizeunittestclasses/filesaroundURIs•  EdgecasetesCng•  DatavalidaCon•  Loggedinversusloggedout

Page 25: Web Application Testing with Selenium for DynDNS.com

MakeChangesEasy

•  OrganizefuncConaltestclassesaroundworkflows•  Createanaccount(mulCplesteps)

•  Buysomething

•  RMA/cancelsomething

•  Provisionsomething

•  Thing1interactswithThing2

Page 26: Web Application Testing with Selenium for DynDNS.com

PlanforFailure

•  Keepunit,regression,funcConal,andverificaContestsseparate

•  IdealisfuncConaltestfailed,andaunittesttoldyouexactlywhatcausedthefailure

•  OrafuncConaltestfailed,andaregressiontesttoldyouyou’veseenthisbugbefore

•  Nodebuggingnecessary

Page 27: Web Application Testing with Selenium for DynDNS.com

PlanforFailure

•  Keepunit,regression,funcConal,andverificaContestsseparate

•  ShortenCmebetweenfailurecreaConandfailurediscovery.

•  Runtestsuitesatdifferentfrequencies/events.

Page 28: Web Application Testing with Selenium for DynDNS.com

AvoidWorkflowOverlap

•  Doasmuchsetupbehindthescenesaspossible– Createanaccountinthedatabaseratherthanform– Addanorderiteminthedatabase…

– Etc.•  Aimtotestjustasingle“thing”pertestcase

•  Refactorprerequisiteworkflowstobaseclasses

Page 29: Web Application Testing with Selenium for DynDNS.com

SeleniumisSlow

•  Raretohaveatestcaseexecuteinlessthan5‐10seconds.

•  Cleanbrowserforeachtestcase.IsolaCon.– HumanCmemorevaluablethanmachineCme.

•  Planaccordingly.•  Openexasperatedbyexternaldependenciesandsystems…

Page 30: Web Application Testing with Selenium for DynDNS.com

Mockup!Unplug!

•  EverythingbutaverificaContestshouldusemocking

•  Mocking– Mockbehaviorofexternalsysteminafastandreproducibleway

– Example:DynDNS.comandcreditcardprocessor– Beabletoreproducespecificerrorresponses!!!– Anyonecanmakesomethingthatworksonsuccess.OurjobistomakeitworkonparCalfailure.