Você está na página 1de 13

GreenLanternAutomationFrameworkfor

TestComplete

Note:Stepbysteptutorialisinprogress.Meanwhileclickonthetitlelinkaboveforasample
guide.

1.Introduction
2.1.Concept
2.2.Chooseelementsforautomatingloginfunction
2.3.Capturetheelementstotherepository
2.4.Renamethelogicalnamesoftheelements
2.5.Categorizetheelementspertheirtype
2.6.TestScripts
2.6.1.RoutineforthefieldUserID
2.6.2.RoutineforthefieldPassword
2.6.3.RoutineforthebuttonSignIn
2.6.4.RoutineforthecheckboxStaysignedIn
2.6.5.Routineverifyingthelogin
2.6.6.Routinecallingalltheloginsteps
3.UserInterfaceChange
3.1.GreenlanternStepsforYahooLogin
3.2.Testrunresults(Logfiles)
4.Afewissueswithconventionalautomation
5.Conclusion

1.Introduction
Manycompanieshaveinvestedintestautomationtoolsinhopesthattheautomationtoolwillfreeup
manpowerbytakingoverregressiontesting.TheautomationtoolslookattheskinsandDOMsofthe
applications.Theyareidentifiedbythepropertiesassignedtotheelements.(Acellcouldbeidentifiedby
theRowandColumn,atablecanbeidentifiedbynumber,alinkcanbeidentifiedwithinnerHTML
ortext,andsoon.)

WhentheskinandtheDocumentObjectModelofanapplicationchangesalotorlittle,itbecomes
unavoidabletoupdateandchangetheautomationscriptsalotoralittletoo.AndiftheapplicationUser
Interfacewascompletelychanged(foranyreason)theautomatedscriptswillneedtoberecreatedfrom
scratch.

Inoneofmyrolesasanautomationengineer,Iwasinchargeforcreatingtestscriptsforthreedifferent
interfacesthatusedthesamebackend.Theirfunctionalitywassame,buttheiruserinterfacewas
completelydifferent.IstartedoffaseverybodycreatingscriptsforeachUserInterface.Butitfeltlike
toomuchhardworkbutliketoolittlesmartwork.So,IneededaframeworkwhereIcouldavoidscript
deathbyeightypercentandincreasereusabilitybyeightypercent.Ineededadisruptiveframework.That
iswhenIcameupwithGreenLanternFramework

UsingtherenamingfeatureoftheautomationtoolthatreliesontheDocumentObjectModel,thetest
scriptscouldbecreatedonceandusednomatterhowmuchtheUserInterfacechangedortheeventhe
DocumentObjectModelchanged.ForexampleautomatedtestscriptscreatedforGmailLoginpagecan
beusedforYahooLoginpage,HotmailLoginpageoranyloginpagewithausernameandpassword.

IwilldemonstratecreatingautomatedscriptsusingGreenLanternframeworkwiththetool
TestCompleteandscriptinglanguageVBScript.

2. GreenLanternSteps

Chooseelementsonthepagethataretargetedforautomation.
Capturetheelementsinarepository
RenametheminEnglishastheywouldappearonthepage
Categorizethempertheirtype(ExampleTextField,Checkbox,Radiobutton,etc.)
Writescriptsusingthepseudonymnames
Writearoutineforeachelement
RoutinesfortextfieldsshouldhavedatacomingfromexternalDatasheets
CheckboxesarecheckedONorOFFviaDataSheets
Logmessages,Warning,Errorsshouldbewritteninthescriptroutine

2.1.Concept
Mainelementsinasoftwareapplicationare
Textfields
Checkboxes
Radiobuttons
Links
Menus
Captions
Images
Logos
Everytestusessomeoralloftheelementsinapage.Theseelementsarecapturedandcategorizedand
namedastheydisplay.Everytestusessomeoralloftheelementsinapage.Whentheseelementsare
capturedandcategorizedandnamedthewaytheywoulddisplay,itiseasytoidentifyeveryelement,easy
towriteascript,easytodetectelementrecognitionfailures,etc.

2.2.Chooseelementsforautomatingloginfunction
ElementsessentialforLoggingintoawebpagearetheURL,thefieldsUserNameandPassword,and
buttonSignIn.

Figure1ChooseelementsnecessaryforthetestfromGmailLoginpage

2.3.Capturetheelementstotherepository
CapturetheelementsthefieldsUserNameandPassword,andbuttonSignInfromtheGmailLogin
page.(ExampleFigure2)


Figure2GmailLoginelementsOriginal

2.4.Renamethelogicalnamesoftheelements
Firefox=MF
GmailLogin=Gmail_Login
Username(inGmail)=UserID
Password=Password
SignIn=SignIn
Staysignedin,=StaySignedIn
Cantaccessyouraccount?=ForgotPasword

Figure3GmailLoginelementsrenamedandcategorized

2.5.Categorizetheelementspertheirtype
Tocategorize,chooseelementpanelLoginbox(whichistheparentelementforallthefield,checkbox,
button,linkelements).DragthiselementandadditunderGmailandrenameitasField.Addelements
UserIDandPasswordundertheField.DragpanelLoginboxagaintoGmailandrenameitas
Checkbox.AddelementStaySignedInundertheCheckbox.DragpanelLoginboxagaintoGmailand
renameitasLink.AddelementForgotPasswordundertheLink.DragpanelLoginboxagainto
GmailandrenameitasButton.AddelementSignInundertheButton.Theendresultwithlooklike
Figure3(Collapsedontherightandexpandedontheleft).

2.6.TestScripts
UsingtherenamedAliaseselements,itwillbeeffortlessanduncomplicatedforanewcomeroran
experiencedprogrammertowritescripts.(NoteNamingtheelementsandcategorizingthemcanbe
decideduponstudyingtheDocumentObjectModel,propertiesofelementsandsuch.)

2.6.1.RoutineforthefieldUserID
Step1.StartwithAliases.
Step2.CallthePageorWebsiteyouwishtouseforthetest.InthisinstanceitisGmail_Loginelement.So
addAliases.Gmail.
Step3.Callthetypeofelementyouwanttouseforthetest.InthisinstanceitistheFieldelement.Soadd
Aliases.Gmail.Field.
Step4.Calltheelementyouwanttouseforthetest.InthisinstanceitistheUserIDelement.Soadd
Aliases.Gmail.Field.UserID
Step5.Callthefunctionthestepissupposedtoperformwiththeelement.Atextboxfieldcaneitherenter
textortypeinKeys.Soadd=Aliases.Gmail.Field.UserID.Keys.
Step6.TextorValuestobeusedcouldbestaticordynamic.Ilikedynamic.Iliketodrivemydatafrom
theexternaldatasheet.Thiswayanymemberoftheteamcancomeupwiththedatatheywouldliketo
use,withoutevertouchingthetestscripts.Soadd=
Aliases.Gmail.Field.UserID.Keys(DDT.CurrentDriver.Value("UserID"))

Step7.IliketoperformafewmorestepsbeforeIinputtheindentedUserID.Iliketoremoveany
preexistingtextthatmightbeinthefield.ForthispurposeIcopypastetheabovecodetwiceandreplace
the(DDT.CurrentDriver.Value("UserID"))with(^a)fromthefirstlinetoselectallthe
existingtext.Replacethe(DDT.CurrentDriver.Value("UserID"))with([Del])from
thesecondlinetodeletealltheexistingtext.Socopyandpasteandmodifythelinesto
Aliases.Gmail.Field.UserID.Keys(^a)Aliases.Gmail.
Field.UserID.Keys([Del])
Step8.InsertamessageinthelogtoknowwhichUserIDwasused.SoaddLog.Message(User
ID=+Aliases.Gmail_Login.Field.UserId.Value)
Step9.Nametheroutinetomatchtheelement.TheendresultwouldlooklikeFigure4.

Figure4RoutineforfieldUserID

2.6.2.RoutineforthefieldPassword
Step1.CopypastetheUserIDroutineandreplacethevalueUserIDwithPassword.Theendresult
wouldlooklikeFigure5.

Figure5RoutineforfieldPassword

2.6.3.RoutineforthebuttonSignIn

Step1.CopyandpastetheUserIDroutine.Removethe2ndand3rdand4thlines.
Step2.ReplacethevalueFieldwithButton.
Step3.ReplacethevalueUserIDwithSignIn.
Step4.ReplacethevalueKeys(^a)withClick().
Step5.InsertamessagetothelogtosuggestbuttonSignInwasclickedon..Soadd
Log.Message("ClickedbuttonSignIn")
Step6.Renametheroutinetomatchtheelementnameandtype.TheendresultwouldlooklikeFigure6.

Figure6RoutineforbuttonSignIn

2.6.4.RoutineforthecheckboxStaysignedIn
Step1.CopyandpastetheSignInroutine.Removethe2ndline.
Step2.ReplacethevalueButtonwithCheckbox.
Step3.ReplacethevalueSignInwithStaySignedIn.
Step4.ReplacethevalueClick()withClick(false).
Step5.InsertamessagetothelogtosuggestthecheckboxStaySignedInwascheckedON.Soadd
Log.Message("UncheckcheckboxStaySignedIn")
Step6.Renametheroutinetomatchtheelementnameandtype.TheendresultwouldlooklikeFigure7.

Figure7RoutineforcheckboxStaySignedIn

2.6.5.Routineverifyingthelogin
TheendresultwouldmoreorlesslooklikeFigure8.

Figure8RoutinetoVerifyLogin

2.6.6.Routinecallingalltheloginsteps
TheendresultwouldmoreorlesslooklikeFigure9.

Figure9RoutinetocombineallelementsforloginFunction
2.6.7.MainroutineforvalidatingthefunctionLogin
Manysteps,ideas,routines,conditions,gointoit.TheendresultwouldmoreorlesslooklikeFigure10and
Figure11.


Figure11ScriptforLoginRoutine
2.7.Testrunresults(Logfiles)
TheendresultofatestrunlogwouldmoreorlesslooklikeFigure12andread
GmailLogInwithBrowserMozillaFirefox

URL=www.gmail.com(URLtextcomesfromdatasheet)
UserID=Srilu.Balla(URLtextcomesfromdatasheet)
Password=
(URLtextcomesfromdatasheet)
GmailInvokedviaMozillaFirefox

Figure12GmailloginTestResult
AlotofworkwentintotheLoginscript.(Phew)

3. UserInterfaceChange

NowimaginetheGmailloginUserInterfacechangesfromGmailtoHotmailoryahoo.Allthetime,effort
andideasputintocreatingtheoriginalscripthavetoberedoneinmostconventionalconditions.Butwith
GreenLanternframeworkthescriptissafeaslongasthereisarepositorythatmatchesit.
IfthealiasesDOMsforHotmailandYahooarepreparedsimilartothealiasesDOMforGmail,the
Scriptswillworkwithlittleornomodificationandlogsimilarmessagesandcheckforsimilarfunctionality.

3.1.GreenlanternStepsforYahooLogin

Step1.CreateRepositoryforHotmailLoginPage
Step2.Renametheelementsandcategorizetembytypeandrenamethelogicalnamestomatchthe
aliasesnamesfortheGmailloginpage.ResultwouldlooksimilartoFigure13.
Step3.CopypastetheLoginScriptforGmailOpenablankscriptandnameitYahoo_LoginandCopy
pastetheGmailLoginScript
Step4.ReplaceGmailwithYahoousingfindandreplace(Ctrl+H)
Step5.Verifythereplacedtextandrunthescript.ResultwouldlooksimilartoFigure14.


Figure13Yahoologinscreenrepository

3.2.Testrunresults(Logfiles)
TheendresultofatestrunlogwouldmoreorlesslooklikeFigure14andread
GmailLogInwithBrowserMozillaFirefox
URL=www.mail.yahoo.com(URLtextcomesfromdatasheet)
UserID=srilu_kiku(URLtextcomesfromdatasheet)
Password=
(URLtextcomesfromdatasheet)
YahooLoginsuccessfulorYahooLoginfailed.

Figure14YahoologinTestResult

4. Afewissueswithconventionalautomation

Mostautomationisrecordandplay.Thistechniquewillexecuteafewstepsonanapplication,butwont
logfulllengthmessages,warningsandwontdocomparisons.


Alotoftimegoesintoautomatingregressionsuits.Alotofeffortgoesintoautomation.Alotofideas
gointoautomation.AllofthiseffortgoeswastewithafewtweakstotheUserInterface.

Severaldevelopers(fromallovertheworld)aredevelopingscriptsforautomation.Unlesstherewasa
codingstandarddefined,eachdeveloperwouldpursuetheirownstyleofrepositorynamingandscript
writing.Theautomationsuitswillnotbeconsistent.

Automatedsuitswithvariouscodingstandardsarehardtomergeandmaintain.

Automatedscriptscreatedforoneapplicationcannotbeusedifchangesaremadetotheapplication.
Theywillneedtobeupdatedaswell.

Atesthadfailedduetorecognitionissues,bylookingatthelogicalnamesintherepositoryorthescript
aloneitisnotenoughtoidentifywhichelementneedsupdating.Becausesometimesseveralelements
couldbenamedsameandseveraltimesthenamesgivenonthepagearenotusedforthelogicalname.

5. Conclusion

Ifthisframeworkisunderstoodcorrectly,engineersusingitcancreateautomationscriptswaybeforethe
applicationisdeveloped.Mostroutinescanbeutilizedoverandoverafterchanginafewnamesinthe
routineswhichcanbeaccomplishedviafindandreplace(Ctrl+H).

Severalapplicationswithsimilarfunctionalitycouldusethesameroutinesandscriptsthatwerealready
created.Now,theengineerandthetesterscancomeupwithmorescenarios.

GreenLanternFrameworkiscompatiblewiththetoolTestComplete.AutomationtoolsQuickTest
Professional,RationalFunctionalTester,Seleniumetcalsocanhavereusablescripts.Theapproachto
thesetoolsvariesfromthecurrentapproachbuttheconceptissimilar.

ChangesintheDOMandtheUserInterfaceofanyapplicationisinevitable.Duringsuchsituations
automationscriptdeathisinevitable.Manyautomationtoolshaveafeaturetorenametheelementsbeing
usedfortests.Whentheseelementsarecleaverlyandclearlyrenamedtosuittheelements(alsomakingit
easytorememberduringscriptcreation),scriptdeathcanbeminimizedoraltogetheravoidedand
simultaneouslythereusabilityofthescriptcanbeincreased.

Iwouldlikemylearnedandknowledgeablecolleaguestotestandquestiontheseideas.Ineedtheir
invaluableadvice,guidanceandparticipationtoenhancethisframeworkandtoimplementonother
automationtools.