说明robot framework学习笔记_第1页
说明robot framework学习笔记_第2页
说明robot framework学习笔记_第3页
说明robot framework学习笔记_第4页
说明robot framework学习笔记_第5页
已阅读5页,还剩37页未读, 继续免费阅读

付费下载

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

简 RobotFrameworkvs.Fitnessevs. 安 使用指 指南(Python 标准测试 nettestlibrary(net库 RobotFramework+ RobotFramework+ 安装 Installation安 Preconditions必备条 Runningthe RobotFramework+ RobotFramework+ RobotFramework与 简 安 Whenusing Whenusing Otheroperating Gettingandrunningthe RobotFramework分布式测 Allcommandline Commandlineoptionsfortest Commandlineoptionsforpost-processing 参考资 easy-to-usetabulartestdatasyntaxandutilizesthekeyword-driventestingapproach.ItstestingcapabilitiescanbeextendedbytestlibrariesimplementedeitherwithPythonorJava,anduserscancreatenew fromexistingonesusingthesamesyntaxthatisusedforcreatingtestcases. IstformandapplicationProvidesacommandlineinterfaceandXMLbasedoutputsforintegrationintoexistingbuildinfrastructure(continuousintegration net,SSH,andso /svn/wiki/publications/QualityMattersQ12009RecentlyIresearchedmanytestingframeworksinordertochooseonetouseatwork.IspentfewdayspracticallytestingthefollowingIchoseRobotFramework.Itisnotperfect,butpromising,extensible,andactivelydevelopedbytheopensourcecommunity.Thefollowingfeaturesmademechoosethisframeworkoverothers:Abilitytousere-Largecollectionofbuilt-Testcasesandsuitesare RobotIDEtestcaseExtendableinPythonandReportingusingHTMLandXMLAllthisgivesasolidbasetoextendandwraparoundinordertocreatestate-of-thearttestingframework.Robotframeworkiseasilyinstallable.Examplesandatonaremorethanenoughtogetautomationengineersandtestersstarted.Itrequiressomelearningandgettingusedto(especiallyRobotIDE)butoncegrasped,creatingtestcasesiseasy.Additionally,new canbesimplyprogrammedinPythonorJython,orcreatedwithexisting (macros).Testsarestartedwithacommandlinetoolandcanbeverysimplyscheduledusingcron.FitNesseframeworkiswidelyusedandpopular,butisnotasextendableasrobotframework.It’satestingwiki.Testcasesarecreatedastablesinwikisandarestartedbyclickingabuttononapage.Theresultsshowupimmediay,butthereisnowaytostorethem.EachtesttablemusthaveacodefixturewritteninJava.OtherlanguagescanbeusedwithahelpofaddtonalFtservers.Beingawiki,FitNessecaotbeusedfoautoaticadoiteactivetestig.AutomationcanbeachievedbyusingcommandlinerunnerorantCucumberisatestingenvironmentthatallowstesterstowrtetestsinaa-specificlanguagebasedonaspokenIt’sbehavior-driven,butallusedsentencesmustbemappedinunderlyingprogramminglanguage(Rubybydefault).It’seasytotranscribeusersstoriesintotestcases,butitrequiresautomatonengineertoworkwithtesterswrtingeverytestcase.Ontheotherhand,it’saveryinterestingandamazingwaytowrteunittests. XML(newinRFThisisalistofpubliclyavailabletestlibrariesthatcanbeusedwithRobotFrameworkbutneedtobeinstalledseparay.Pleaserefertotheindividualprojectpagesforinformationaboutinstallingandusingthem. waretoolasaDatabaseLibrary(Java)-Atestlibrarythatprovidescommonfunctionalityfortestingdatabasecontents.ImplementedusingJavasoworksonlywithJython.How-To:SikuliandRobotFrameworkIntegration-ThisisnotreallyalibrarybuttheseinstructionsexinhowtointegrateSikulitoolwithRobotFrameworkFoundthesealso,mightbeusefultoaddthemaswell(totheexternalIOS Sikuliintegrationlibrarieshereandhere(Thehow-toishelpful,butnotexactlyalibrary.Checkouthereforcodebasedonthehow-to Windows下的一键安装: /p/robotframework/wiki/Installation#OneClick在[PythonDir]\Lib\site-packages\robot\utilsencoding.py文件中,找到def_get_output_encoding():原来的编码是’cp437’将其改成’cp936’(简体中文,gbk)。/hg/doc/userguide/RobotFrameworkUserGuide.html?r= D:\AgileTesting\RobotFramework\quickstart /hg/doc/libraries/OperatingSystem.html?r=2.7.7OperatingSystemisRobotFramework'sstandardlibrarythatenablesvariousoperatingsystemrelatedtaskstobeperformedinthesystemwhereRobotFrameworkisrunning.Itcan,amongotherthings,executecommands(eg.Run),createandremovefilesanddirectories(e.g.CreateFile,RemoveDirectory),checkwhetherfilesordirectoriesexistsorcontainsomething(eg.FileShouldExist,DirectoryShouldBeEmpty)andmanipulateenvironmentvariables(eg.SetEnvironmentVariable).

/svn/wiki/publications/testingexperience0109 netisRobotFramework'sstandardlibrarythatmakesitpossibletoconnectto serversandexecutecommandsontheopenedconnections.Thefulllibraryationbyreleaseisfoundbelow.Theationofthelatestminorversion(e.g.2.0.4)isalwaysapplicablewithearlierminorversions.RobotFramework+ AutoItLibraryisaPythonkeywordlibrarythatextendsRobotFrameworkbyproviding basedontheCOMinterfacetoAutoIt,awaretoolforautomatingtheWindowsGUI.IfyouarenotusingActivePython,whichcomeswiththePythonforWindowsextensionssuchas ,thenyou'llneedtoinstallMarkHammond'sPythonforWindowsExtensions.AutoItLibraryinstallsitsownfilesandtherequiredpartsofAutoIt.Toinstall,unzipthedownloadedsourcereleasefileintoatemporarydirectoryonyourPC,openacommandwindowinthatdirectoryandtype:NOTEInWindowsVistaandWindows7youmustdothisinstallationasAutoItLibraryrequires .See需要 RobotFramework+ UsingtestlibrariesimplementedwithJavaorusingJavatoolsinternallyrequiresrunningRobotFrameworkonJython,whichinturnrequiresJavaRuntimeEnvironment(JRE).StartingfromRobotFramework25,theminimumsupportedJythonversionis2.5whichrequiresJava1.5(a.k.a.Java5)ornewer.EarlierRobotFrameworkversionssupportalsoJython2.2.InstallingJythonisafairlyeasyprocedure,andthefirststepisgettinganinstallerfromtheJythonhomepage.TheinstallerisanexecutableJARpackage,whichyoucanrunfromthecommandlinelikejava-jarjython_installer-<version>.jar.Dependingonthesystemconfiguration,itmayalsobepossibletojustdouble-clicktheinstaller.RunningRobotFrameworkonJythonusingthejybotstart-upscriptrequiresjythontobeexecutabledirectlyinthesystem.ThismeansthatyouneedtomakesureitisinPATH. JDave‐BDDframeworkforJava InstallationPreconditionsInstallNETFrameworkWehaveonlytestedwiththe4.0seriesbutearlierandnewerversionsshouldworktooassumingyoucaninstallIronPythononthem.(安装,NETFramework4.0)InstallIronPythonWehavetestedwith26.2and2.7releasesbutpossiblenewer2.6.xand2.7.xreleasesoughttoworktoo.(安装IronPython2.7)Installthesourcedistributionofelementtreemodule.Wehaveonlytestedwiththe1.2.7previewrelease,whichshouldhavebetterIronPythonsupportthan1.2.6.SeeInstallingPythonmodulessectionbelowforinstallationinstructions.IfyouareusingIronPython2.6.xwithRobotFramework2.6.3ornewer,installIronPython.Zlibmodule.ThismoduleisincludedintoIronPython2.7soseparateinstallationisnotneededwiththatrelease.InstallingPythonGetandextractthesourcedistributionpackageofthemoduleyouwanttoinstallAlternativelyyoumaybeabletocheckoutthesourcecodedirectlyfromtheproject'sversioncontrol.(elementtree1.2.7previewrelease、robotframework-2.7.7.tar.gz)GototheextractedorcheckedoutdirectoryfromthecommandInstallthemodulewithcommandipysetup.pyinstall.IfyoudonothaveipyinPATH,youneedtouseafullpathtoit.WithIronPython2.6.xyoualsoneedtoadd pileoptionlikeinipysetup.pyinstall RunningtheCreateafileipybot.batasfollows.Makesuretorece[IRONPYTHON_INSTALL_FOLDER]withtheinstallationpathofIronPythononyour::::IronPythonexecutabletoset::Pathto::RunRobotonIronPython%ironpython%%runner%Thisfileemulatesthepybot.batthatcomeswiththeinstallationoftheRobotframeworkonPython.Oncealltheotherfileshavebeencreatedandcopiedtothesamedirectory,runthecommand:ThedemoapplicationisaverysimpleC#classwhosetwomethodssimplyaddtwonumbersandconcatenatetwostrings,spacenamespace{publicclass{publicintAddNumbers(intnumber1,int{returnnumber1+}}publicstringAddStrings(stringstring1,string{returnstring1+""+}}}Asimpletestlibrarythatcaninctwiththeaboveusingthe.NetCLR.Themethods’namesinthatlibrarywillactas fortheRobotimportimportclr.AddReferenceToFileAndPath('Combine.dll')#includefullpathtoDllifrequiredfromTestimportCombineintNum1=int(num1)intNum2=raiseException("Valuesmustbeintegernumbers!")cmb=Combine()total=cmb.AddNumbers(intNum1,intNum2)returnstr(total)cmb=Combine()***Settings***TestCases oShouldBeShouldBeRobotFramework+ SeleniumLibraryisaRobotFrameworktestlibrarythatusesthepopularSeleniumwebtestingtoolinternally.Itprovidesapowerfulcombinationofsimpletestdatasyntaxandsupportfordifferentbrowsers.Inadditiontostandardwebtesting,thelibraryalsosupportstestingAdobeFlex/Flashapplications.SeetheSeleniumLibrarydemoforexecutableexampletestcasesandreports,lookatthelibrary ationforinformationabouttheprovided ,andconsulttheinstallationinstructionsifyouwanttousethelibrarySelenium1vs.SeleniumSeleniumLibraryinternallyusesSeleniumRemoteControllerAPIthatispartofSelenium1.IfyouwanttousethenewSelenium2WebDriverAPI,youshouldlookatSelenium2Librarythatis,formostparts,adrop-in-recementforSeleniumLibrary.Accordingto,theoldRemoteControllerAPIisofficiallydeprecatedinfavorofthenewWebDriverAPI.AsaresultalsoSeleniumLibraryisdeprecatedandnonewreleasesareexpected.NewusersshouldusethealreadymentionedSelenium2Libraryandexistingusersshouldstarttonmigratingtoit. ***SettingsSuiteSetup StartSeleniumServerSuiteTeardownStopSeleniumServer ***TestCases***open 按F8执Pybot SudsLibraryisalibraryforfunctionaltesingofSOAP-basedwebservices.SudsLibraryisbasedonSuds,adynamicSOAP1.1 Thislibraryisinabetadevelopmentstage.SeetheKeywordationformoreinformationaboutusingthepipinstallpipinstall***Settings ***TestCases***CreateSoap${dblarray}= CreateWsdlObject AppendToList ${dblarray.double} ${dbl CallSoapMethod ShouldBeEqualAsNumbers robotframework-httplibraryisaRobotFrameworktestlibraryforallyourHTTPneeds.Ituseslivetest(which,inturnusesthefamouswebtestlibraryunderneath).pippipinstall‐‐upgradeAPIationcanbefoundat /robotframework-httplibrary/,hereisanexampleonhowtouseFollowsaYoucanviewareportandalogofthistestexecutedthatlookslikeRequestsLibraryisaRobotFrameworktestlibrarythatusestheRequestsHTTPYouneedtohaverequestsNOTE:Onlysupportrequests0.9.0orpippipinstall‐Upipinstall‐Um/= Youcaninstallthelatesttrunkby$$sudo$$sudopythonsetup.pyRobotFrameworkPython实现的文档太少了,搞通它得费一番周折。在折腾了一段时间后我终于把它调通顺了,做个记录,也希望能帮助别人迅速解决问题。需要说明的是:我是用的oracle数据库。 .cn/s/blog1 。任何一个RobotFrameworkLibrary基本上都是一个双层结构:外层的皮,实现标准接口供RobotFramework调用;里面的瓤,实现具体的功能,提供API供外层的皮进行封装。 cx_oracle并安装。我选择的是Windowsx86Installer(Oracle10gPython2 2 ,执行setuppy在RideSettinVaLibrTestCaActiArgumentConnectTeConnectToUsingCustom select*fromtable1Log 这样我们就完成了第一个选择table1ConnectToDatabaseUsingCostomParamscx_Oracle这个库,所以第一个参数指定它;第二个参数是连接串用户名,,和要连接的Oracle数据库的本地服务命名(与你oracle\network\admin\tnsnamesora文件中的描述相对应)。cx_Oracle依赖Oracle的客户端环境,这点需要注意。Logcx_OracleUtf-8。需要人工转换一下。DataBaseLibraryDataBaseLibrary进行扩展了。打开安装下的querypy文件,def都做一下decode。例如不能ContentForRowIdentifiedByWhere

‐dblibrary/DatabaseLibrary dblibrary-10jar这个库文件在Oracle的主页的download中找到JDBC的驱动程序 的jdbc子 TestConnecttofor%%jin(*jar)do(call:set_cp%%j)setCLASSPATH=%CP%jybot--outputdir�%--suitestatlevel1gotogoto:eof这个codeSVN SSHLibraryisatestlibraryforRobotFramework.ItenablesexecutionofcommandsonaremotemachineoveranSSHconnection.Italsoofferspossibilitytotransferfilesfromandtoaremotemachine.SSHLibraryworkswithbothPythonandJythoninterpreters,butitrequiresSSHmodulestobeinstalledseparay.WithPythonyouneedParamiko(whichinturnrequiresPyCrypto),andwithJythonTrileadSSHisrequired.Formoreinformationseeinstallationinstructions.WhenusingPythonApreconditionforusingSSHLibrarywithPythonishavingSSHnamedparamikoinstalled.Paramikoitselfhassomeotherrequirementslistedininstallationinstructions(mainlyPyCrypto)andthesemustnaturallybeinstalledtoo.PyCryptobinariesforWindowsareavailableherefor32bitWindowsandherefor64bitWindows.InWindows,paramikohastobeinstalledfromthesourcedistribution,byunzipthedownload,andthenrunningpythonsetup.pyinstallintheunzippeddirectory.WhenusingParamikodoesn'tworkwithJython,butTrileadSSHforJavacanbeusedinstead.TheJARpackagecontainingTrileadSSHtoolmustbefoundfromtheCLASSPATHduringthetestSeeRobotFrameworkuserguideformoreinformationaboutsettingtheenvironmentfortestInstallingSSHSSHLibraryisinstalleddifferentlyonWindowsandonotheroperatingInstallingusingWindowsbinaryinstallerisreallystraightforward,justdoubleclicktheprovidedWindowsinstallerandfollowtheinstructions.OnotheroperatingsystemsSSHLibrarymustbeinstalledusingasourcedistribution.Theprocedureisfollowing:ExtractthesourcedistributionOpenconsoleandgotheresultingRuncommandpythonsetup.pyRootprivilegesmayberequiredforthe ThissimpleexampledemonstrateshowtouseClanguagefromRobotFrameworktestlibraries.TheexampleusesPython'sstandardctypesmodule,whichrequiresthattheCcodeiscompiledintoasharedlibrary.ThisversionisimplementedandtestedonLinux,butadaptingittootheroperatingsystemswouldrequireonlychangingcompilationandnameoftheproducedsharedlibrary.GettingandrunningtheTheexampleisavailableonthedownloadpageasrobotframework-c-example-<date>.zip.Afterdownloadingandunzipthepackage,youshouldhaveallthefilesinadirectoryrobotframework-c-example.Totryouttheexamplefirstrunmakeinthedirectorythatwascreatedwhenyouunzippedthepackage.Thiswillcreatelibraryliblogin.so,asharedlibrarythatisneededtousectypesmodule.TheexampletestscanbeexecutedusingcommandpybotLoginTests.tsv.Allthetestshouldpass.Thedemoapplicationisaverysimpleloginsystem,implementedusingC,thatvalidatesthegivenusernameandpasswordandreturnsthestatus.Therearetwovalidusernamepasswordcombinations:demo/modeandjohn/long.#defineNR_USERS2structUserconstchar*name;conststructUserVALID_USERS[NR_USERS]={"john","long","demo","mode"intvalidate_user(constchar*name,constchar*{intfor(i=0;i<NR_USERS;i++)if(0==strncmp(VALID_USERS[i].name,name,if(0==strncmp(VALID_USERS[i].password,password,strlen(VALID_USERS[i].password)))return1;}return}fromfromctypesimportCDLL,LIBRARY=CDLL('./liblogin.so')#OnWindowswe'dusedefdefcheck_user(username,"""ValidatesusernameandpasswordusingimportedsharedClibrary."""ifnotLIBRARY.validate_user(c_char_p(username),c_char_p(password)):ifname=='main':importsysexceptTypeError:print'Usage:%susernamepassword'%sys.argv[0]exceptAssertionError,err:print'ValidTheifname=='main'blockaboveisnotusedbytheexecutedtests,butitallowsusingthelibrarycodeasatoolformanualtesting.thecommandline.***Settings***TestCaseValidateCheckValidCheckValidLoginWithInvalidUserShouldCheckInvalidCheckInvalidCheckInvalidCheckInvalid***KeywordCheckValidCheckCheckInvalidRunKeywordAndExpectCheck WehavebeenusingRobotFrameworkatmyceofworkforseveraloverayearnowwithmoderatesuccess.Liketheposter,wealsodoC++work.WetooksometimetoevaluateRobotagainstFitnesse/Slimand,atthetime,bothsolutionsweregood,butthedecidingfactorswere(asof~2009):ItwasclearerhowRobotanditsreportswouldscaletolargeItwasn'tobvioushowtoversioncontrolFitnesseFromatechnical,wehavebeenusingSWIGtobridgebetweenRobotandC++.WewrapourtestfixturesinSWIGandlinkitwiththeproductioncodeundertest-givingusapythonmodulethatcanbeimportedbyRobot.Weusethe.txtformatforRobotinputalmostexclusively-we'vefoundthatthisversioncontrolsbetter,it'seasiertoread,andwesimplyweren'tusingtheadvancedfeaturesofHTML(whichiswherewestarted).Inaddition,weareusingthe"BDDStyle"Robotsyntaxaswell.WeuseMockwithsomewrapperstohelpussetexpectationswhicharecheckedduringtheteardownofeachRobottest.Asfarasorganizingthetests,wehavesettledonthefollowingapproach(withinspirationfromDaleEmery'sapproachgivenhere):MajorfunctionalhierarchyisrepresentedbyafolderAfeature-ishsizedthingisdescribedinaRobottestfileAdescriptionofeachpartofthatfeatureisusedattheRobottestcaseAnexampleisgivenasthestepsinthetestTheexampletextisbrokendownintostepsusingRobot ThetestfixturedrivestheproductionForexample,aphonemighthavesomethinglike////***TestCaseAusercandialaUSnumberwithanareacode,upto10GivenGivenaphonewithoutanynumbersExpecttheattemptedphonenumbertobeWhenauserentersthe//Aseparate***Keyword.txtorsomethingGivenaphonewithoutanynumbers Expecttheattemptedphonenumbertobe${phoneNumber}Whenauserentersthenumbers //MakingCallsFixture.cpp(whichgetswrappedby{...Driveproductioncode}//CreateNewDialer,ExpectDialedNumberalsogoWewouldthenpairthisupwithunitteststhatcoverthecornerconditions(e.g.ensurenomorethan10digitsareallowed)-ormaybethatwouldbeanotheracceptancetest(executablespec)dependingonwhoisreadingthetestsandtheirfamiliaritywiththe.Wecreateadraftofthesespecsandreviewwithexpertsandtheteampriortobeginningwork.Thishashelpedflushoutanumberofmisunderstandingsearlyon.参考:RobotFramework /hg/doc/userguide/RobotFrameworkUserGuide.html?r=Itisalsopossibletowritetestcasesasrequirementsthatalsonon-technicalprojectstakeholdersmustunderstand.TheseExecutableRequirementsareacornerstoneofaprocesscommonlycalledAcceptanceTestDrivenDevelopment(ATDD).Onewaytowritetheserequirements/testsisGiven-When-ThenstylepopularizedbyBehaviorDrivenDevelopment(BDD).Whenwritingtestcasesinthisstyle,theinitialstateisusuallyexpressedwithakeywordstartingwithwordGiven,theactionsaredescribedwithkeywordstartingwithWhenandtheexpectationswithakeywordstartingwithThen.KeywordstartingwithAndmaybeusedifastephasmorethanoneGivenloginpageisWhenvalidusernameandpasswordareandcredentialsare epageshouldbeIgnoringGiven/When/Then/AndPrefixesGiven,When,ThenandAndaredroppedwhenaresearched,ifnomatchwiththefullnameisfound.Thisworksforboth andlibrary .Forexample,GivenloginpageisopenintheaboveexamplecanbeimplementedasuserkeywordeitherwithorwithoutthewordGiven.Ignoringprefixesalsoallowsusingthesamekeywordwithdifferentprefixes.Forexample epageshouldbeopencouldalsousedasAnd epageshouldbeopen.EmbeddingdataWhenwritingconcreteexamplesitisusefultobeablepassactualdatatokeywordimplementations.User supportthisbyallowingembeddingargumentsintokeywordRobotFramework+JDave‐BDDframeworkforGiven/When/ThenAndExampleTablesUsingtheRobotpybot|jybot|ipybot[options]data_sourcespython|jython|ipypybot|jybot|ipybot[options]data_sourcespython|jython|ipy-mrobot.run[options]data_sourcespython|jython|ipypath/to/robot/run.py[options]data_sourcesjava-jarrobotframework.jar[options]data_sources AllcommandlineThisappendixlistsallthecommandlineoptionsthatareavailablewhenexecutingtestcaseswithpybotorjybot,andwhenpost-processingoutputswith Commandlineoptionsfortest Commandlineoptionsforpost-processingCommandlineoptionsfortestSetsthenameofthetop‐leveltest‐D,‐‐doc<Setstheationofthetop‐leveltestSetsmetadataforthetopleveltest‐G,‐‐settagSetsthetag(s)toallexecutedtest‐t,‐‐testSelectsSelectsthetestcasesbySelectsthetestsuitesbySelectsthetestcasesbySelectsthetestcasesbyTeststhathavethegiventagareconsideredTeststhathavethegiventagarenotSetsindividualSetsvariablesusingvariableDefineswheretocreateoutputSetsthepathtothegeneratedoutput‐l,‐‐logSetsthepathtothegeneratedlogSetsthepathtothegeneratedreportSetsthepathtothegeneratedXUnitcompatibleresultAdebugfilethatiswrittenduringAddsatimestamptoalloutput SplitlogfileintosmallerpiecesthatopeninbrowserSetsatitleforthegeneratedtestSetsatitleforthegeneratedtestS

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论