Selenium.docx

上传人:b****8 文档编号:10621902 上传时间:2023-02-21 格式:DOCX 页数:30 大小:29.64KB
下载 相关 举报
Selenium.docx_第1页
第1页 / 共30页
Selenium.docx_第2页
第2页 / 共30页
Selenium.docx_第3页
第3页 / 共30页
Selenium.docx_第4页
第4页 / 共30页
Selenium.docx_第5页
第5页 / 共30页
点击查看更多>>
下载资源
资源描述

Selenium.docx

《Selenium.docx》由会员分享,可在线阅读,更多相关《Selenium.docx(30页珍藏版)》请在冰豆网上搜索。

Selenium.docx

Selenium

SeleniumUI-ElementReference

Introduction

UI-ElementisaSeleniumfeaturethatmakesitpossibletodefineamappingbetweensemanticallymeaningfulnamesofelementsonwebpages,andtheelementsthemselves.ThemappingisdefinedusingJavaScriptObjectNotation,andmaybesharedbothbytheIDEandtestsrunviaSeleniumRC.Italsooffersasinglepointofupdateshouldtheuserinterfaceoftheapplicationundertestchange.

Terminology

Page

AuniqueURL,andthecontentsavailablebyaccessingthatURL.Apagetypicallyconsistsofseveralinteractivepageelements.ApagemayalsobeconsideredaDOMdocumentobject,completewithURLinformation.

Pageelement

Anelementontheactualwebpage.Generallyspeaking,anelementisanythingtheusermightinteractwith,oranythingthatcontainsmeaningfulcontent.Morespecifically,anelementisrealizedasaDocumentObjectModel(DOM)nodeanditscontents.Sowhenwerefertoapageelement,wemeanbothofthefollowing,atthesametime:

∙somethingonthepage

∙itsDOMrepresentation,includingitsrelationshipwithotherpageelements

Pageset

Asetofpagesthatsharesomesetofcommonpageelements.Forexample,Imightbeabletologintomyapplicationfromseveraldifferentpages.Ifcertainpageelementsoneachofthosepagesappearsimilarly(i.e.theirDOMrepresentationsareidentical),thosepagescanbegroupedintoapagesetwithrespecttothesepageelements.Thereisnorestrictiononhowmanypagesetsagivenpagecanbeamemberof.Similarly,aUIelementbelongtomultiplepagesets.ApagesetiscommonlyrepresentedbyaregularexpressionwhichmatchestheURL'sthatuniquelyidentifypages;however,therearecaseswhenthepagecontentmustbeconsideredtodeterminepagesetmembership.Apagesetalsohasaname.

UIelement

Amappingbetweenameaningfulnameforapageelement,andthemeanstolocatethatpageelement'sDOMnode.Thepageelementislocatedviaalocator.UIelementsbelongtopagesets.

UIargument

AnoptionalpieceoflogicthatdetermineshowthelocatorisgeneratedbyaUIelement.Typicallyusedwhensimilarpageelementsappearmultipletimesonthesamepage,andyouwanttoaddressthemallwithasingleUIelement.Forexample,ifapagepresents20clickablesearchresults,theindexofthesearchresultmightbeaUIargument.

UImap

Acollectionofpagesets,whichinturncontainUIelements.TheUImapisthemediumfortranslatingbetweenUIspecifierstrings,pageelements,andUIelements.

UIspecifierstring

Abitoftextcontainingapagesetname,aUIelementname,andoptionallyargumentsthatmodifythewayalocatorisconstructedbytheUIelement.UIspecifierstringsareintendedtobethehuman-readableidentifierforpageelements.

Rolluprule

LogicthatdescribeshowoneormoreSeleniumcommandscanbegroupedintoasinglecommand,andhowthatsinglecommandmaybeexpandedintoitscomponentSeleniumcommands.Thesinglecommandisreferredtosimplyasa"rollup".

Commandmatcher

Typicallyfoldedintoarolluprule,itmatchesoneormoreSeleniumcommandsandoptionallysetsvaluesforrollupargumentsbasedonthematchedcommands.Arollupruleusuallyhasoneormorecommandmatchers.

Rollupargument

Anoptionalpieceoflogicthatmodifiesthecommandexpansionofarollup.

TheBasics

GettingMotivated

Question:

WhyuseUI-Element?

Answer:

Soyourtestcasescanlooklikethis(boilerplatecodeomitted):

open

/

clickAndWait

ui=allPages:

:

section(section=topics)

clickAndWait

ui=topicListingPages:

:

topic(topic=Process)

clickAndWait

ui=subtopicListingPages:

:

subtopic(subtopic=Creativity)

click

ui=subtopicArticleListingPages:

:

article(index=2)

IncludingtheRightFiles

UI-ElementisnowfullyintegratedwithSelenium.Theonlyadditionalfilethatneedstobespecifiedisyourmapdefinitionsfile.IntheIDE,addittothecomma-delimitedSeleniumCoreextensionsfieldoftheIDEoptions.Asampledefinitionfilecreatedforthewebsiteisincludedinthedistributionandisavailablehere:

chrome:

//selenium-ide/content/selenium-core/scripts/ui-map-sample.js

YoumightwanttoexperimentwiththesamplemaptogetafeelforUI-Element.FortheSeleniumRC,youhavetwooptions.Themapfilemaybeincludedintheuser-extensions.jsfilespecifiedatstartupwiththe-userExtensionsswitch.Or,youmayloaditdynamicallywiththevariantofthesetUserExtensionJscommandinyourdriverlanguage,beforethebrowserisstarted.

MapDefinitionsFileSyntax

Thisisthegeneralformatofamapfile:

varmap=newUIMap();

map.addPageset({

name:

'aPageset'

...

});

map.addElement('aPageset',{...});

map.addElement('aPageset',{...});

...

map.addPageset({

name:

'anotherPageset'

...

});

...

ThemapobjectisinitializedbycreatinganewUIMapobject.Next,apagesetisdefined.ThenoneormoreUIelementsaredefinedforthatpageset.Morepagesetsaredefined,eachwithcorrespondingUIelements.That'sit!

PagesetShorthand

ThemethodsignatureofaddPageset()is(pagesetShorthand).pagesetShorthandisaJSONdescriptionofthepageset.Here'saminimalexample:

map.addPageset({

name:

'allPages'

description:

'containselementscommontoallpages'

pathRegexp:

'.*'

});

Here'satablecontaininginformationabouttheattributesofthePagesetobject.TheconditionallyrequiredorunrequireditemsareforIDErecordingsupportonly.

Name

Required?

Description

Example

name

Yes

(String)thenameofthepageset.Thisshouldbeuniquewithinthemap.

name:

'shopPages'

description

Yes

(String)adescriptionofthepageset.Ideally,thiswillgivethereaderanideaofwhattypesofUIelementsthepagesetwillhave.

description:

'allpagesdisplayingproduct'

pathPrefix

No

(String)thepathoftheURLofallincludedpagesinthispagesetwillcontainthisprefix.Forexample,ifallpagesareoftheformthepageprefixmightbegallery/.

pathPrefix:

'gallery/'

paths

pathRegexp

Conditional

(Array|String)eitheralistofpathstrings,orastringthatrepresentsaregularexpression.Oneortheothershouldbedefined,butnotboth.Ifanarray,itenumeratespagesthatareincludedinthepageset.Ifaregularexpression,anypageswhoseURLpathsmatchtheexpressionareconsideredpartofthepageset.Ineithercase,thepartoftheURLbeingmatched(calledthepath)isthepartfollowingthedomain,lessanytrailingslash,andnotincludingtheCGIparameters.Forexample:

Theentirepathmustmatch(however,pathPrefixistakenintoaccountifspecified).Ifspecifiedasaregularexpression,thetworegularexpressioncharacters^and$markingthestartandendofthematchedstringareincludedimplicitly,andshouldnotbespecifiedinthisstring.Pleasenoticetoothatbackslashesmustbebackslash-escapedinjavascriptstrings.

paths:

[

'gotoHome.do'

'gotoAbout.do'

'gotoFaq.do'

]

pathRegexp:

'goto(Home|About|Faq)\\.do'

paramRegexps

No

(Object)amappingfromURLparameternamestoregularexpressionstringswhichmustmatchtheirvalues.Ifspecified,thesetofpagespotentiallyincludedinthispagesetwillbefurtherfilteredbyURLparametervalues.Thereisnofilteringbyparametervaluebydefault.

paramRegexps:

{

dept:

'^[abcd]$'

team:

'marketing'

}

pageContent

Conditional

(Function)afunctionthattestswhetherapage,representedbyitsdocumentobject,iscontainedinthepageset,andreturnstrueifandonlyifthisisthecase.Ifspecified,thesetofpagespotentiallyincludedinthispagesetwillbefurtherfilteredbycontent,afterURLandURLparameterfiltering.

SincetheURLisavailablefromthedocumentobject(document.location.href),youmayencodethelogicusedforthepathsandpathRegexpattributesallintothedefinitionofpageContent.Thus,youmaychoosetoomittheformerifandonlyifusingpageContent.Ofcourse,youmaycontinuetousethemforclarity.

pageContent:

function(doc){

varid='address-tab';

returndoc.getElementById(id)!

=null;

}

UI-ElementShorthand

ThemethodsignatureofaddElement()is(pagesetName,uiElementShorthand).pagesetNameisthenameofthepagesettheUIelementisbeingaddedto.uiElementShorthandisacompleteJSONdescriptionoftheUIelementobjectinshorthandnotation.

Initssimplestform,aUIelementobjectlookslikethis:

map.addElement('allPages',{

name:

'about_link'

description:

'linktotheaboutpage'

locator:

"//a[contains(@href,'about.php')]"

});

Here'satablecontaininginformationabouttheattributesoftheUIelementobject.Theasterisk(*)meansanystring:

Name

Required?

Description

Example

name

Yes

(String)thenameoftheUIelement

name:

'article'

description

Yes

(String)adescriptionoftheUIelement.ThisisthemaindocumentationforthisUIelement,sothemoredetailed,thebetter.

description:

'frontorissuepagelinktoarticle'

args

No

(Array)alistofargumentsthatmodifythegetLocator()method.Ifunspecified,itwillbetreatedasanemptylist.

[

{name:

'index'

description:

'theindexoftheauthor,byarticle'

defaultValues:

range(1,5)}

]

Seesectionbelowelaboratingonattributesofargumentobjects.

locator

getLocator()

xpathgetXPath()

Yes

(String|Function)eitherafixedlocatorstring,orafunctionthatreturnsalo

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 求职职场 > 简历

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1