自動化測試總結_第1頁
自動化測試總結_第2頁
自動化測試總結_第3頁
自動化測試總結_第4頁
自動化測試總結_第5頁
已閱讀5頁,還剩3頁未讀 繼續免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

1、自動化測試學習總結Selenium的簡單介紹Selenium是一套不同的軟件工具,使用不同的方法來支持自動化測試。許多 selenium QA Engineers專注于一個或兩個滿足他們項目需求的工具,然而學 習所有的工具將給他們解決不同的測試問題提供許多不同的選項。整套工具提供 了非常豐富的功能,可以滿足各種種類的Web應用的測試需求。這些操作非常靈 活,允許有多種定位UI元素和比較期望結果的方法。Selenium的一個關鍵特性 是一個測試案例可以在多個操作系統平臺上運行。要不要自動化自動化永遠都有優勢么?什么時候應該選擇自動化?不,有時候手工測試更適合。例如,如果應用的用戶界面在不遠的將來

2、會改 變,那么自動化需要重寫?;蛘?,沒有足夠的時間來創建自動化測試。短期來說, 手工測試更有效率。如果一個應用有很緊的期限,暫時沒有自動化測試,而且測 試必須在一個時間段里完成,那么手工測試是最好的選擇。Selenium自動化測試的好處頻繁的回歸測試快速的反饋Test Case幾乎無限次的執行支持Agile和Extreme開發模式Test Case的有紀律的文檔定制的缺陷報告尋找被手工測試忽略的缺陷學習的目的本次主要是對功能測試工具Selenium2 Webdriver的學習和使用,作為一個 之前沒接觸過selenium的新手,本次主要圍繞Selenium對其測試框架進行挖掘, 其次就是對于j

3、ava語言的回顧和學習。學習過程中用到的軟件及插件瀏覽器使用的 FireFox35.0.1,Selenium IDE,Firebug,FirePathWebdriver+eclipse+Junit+testNG+reportNG,測試結果的控制(Excel 測試用例).testn g.eclips e_6 9.10.: n sorg .testn g.ecli psej qg .testn g.ecli pse_6.9 org .testn g.ecli pse_6. 使用的jar包.testn g.eclips e_6 9.10.: n sorg .testn g.ecli psej qg

4、.testn g.ecli pse_6.9 org .testn g.ecli pse_6. : Qic testng.jar - L:UsersvrvDesktopeclip5e-jee-mars-K-wino2ecl 1 psepIug 1 nsor(冒 jcommander.jar - C:U sersvrvDes Icto pecli pse-jee- mars- R-win32ecli psep I u g咨 bsh-2.0b4.jar - C:UsersvrvDesktopeclipse-jee-mars-R-win32eclipsepluginsm snakeyaml.jar -

5、 C:UsersvrvDesktopeclipse-je-e-mars-R-/.!n32eclipsepIuginB. Referenced Libraries皿 selenium-seirver-standalone-2.43.1.jar - C:UsersvrvDesktopTM窟 selenium-java-2.42.2.jar - C:UsersvrvDesIctopT-B:jxl.jar - C:UsersvrvDesktop0心 roboguice-S.O.l.jar - C:LJsersvrvDesktop叩 repoirtn g -1.1.4.j a r - C:U 5 ers

6、vrvD es kto p在Eclipse IDE中建立一個Java project,建立如下的文件夾結構,com data unitA JRE System Library JavaSE-1.7TestNG也 Referenced Libraries臼? test-output 圖Login.xls)velocity.log編寫Web應用程序的單元測試用例,如下所示/BeforeBeforeSuitepublic void setUpf) throws Exception driver=new FirefoxDriverf);driver.manage().windowf).maximize

7、f);d rive r.ma n a ge()-timeoutsf).implicitlyWait(3j Time Un it-SECONDS);driver“ get(url+/vdsm);Thread.steep;Testpublic void test() throws InteriruptedException crsse rtTrue (IsE leme nt Pre sent (By.su bmit *);d rive r. findE leme nt (By. id(uac cou nt) -clearf);driver.findElement(By.id(usubmit) -c

8、lick();Thread.steep(2000);Syst em. out. pint In (”此/為建新項:+d river. findE lement ( By xpath ( / html/body/ div2/spanl1). getT ext(). cont 2n s (重為建新項祈 driver,findElement(By.id(account) .sendKeys(Im);driverfindElement(By.id(submit) - diek();Thread.steep(2000);Syst em. out. print In (11 踏為 JMt 耍*+d riv

9、er , fin dE lement ( By xpath ( / html/body/div2/spanl). getT ext(). cont ains(設初頃削 d rive r. findE leme nt (By. id(uac cou nt) -clearf);driver . findElement (By. id(password) clearf);d rive r. findE leme nt (By. id(*ac cou nt) .send Keys ( W d min );d rive r. findE leme ntfBy.idfpas sword *) .send

10、Keys (vs e cvrv c o mu);driver,findElement(By.id(submit) -click();Thread.steep(2000);Syst em. out. print In (主上角捏宙 y 魁+d rive r. fin dE lement (By. t言頁”).getT e xt () cont 曰比 5 (苜頁);d rive r. f i n d E leme nt ( By. xpath (/a on c lie k= * logout (); )-clickf);Thread.5teep(2000);protected boolean Is

11、ElementPresent(By by) try driver,findElement(by);return true; catch (Exception e) return false;此為Junit框架,該框架只適合單元測試。采用testNG可對同一業務流程多個測試用例同時進行測試,如下圖所示(0Testpublic void testl() throws InterruptedEKception boolean strl=unit. isWebElementExist (By.submitIF);tew.write(new File(IF Login. xlsIF) Login1 41

12、, strl);(fflTestpublic void test2() throws InterruptedException unit. clear (By. id( accountIF);unit. cliclc(By.subnit) jThreads sleepflWO);boolean str2=unit. signfBy.xpE(/htmL/bocly/1cliM2/wpan.)_l tew.write(nw File(Login .xls) j1login11 j 42, str2);?(STestpublic void test3() throws InterruptedExce

13、ption unit. sendKeysfBy. id( accountIF)j admin);unit. click(By. subnit);Thread s/,eep(20);boolean str3=unit. sign By. xpath /html/bodly/d iv 2 /s pa n 1 ) jtew-write(new File (IF Login . xlsIF) j IFloginIFj 4j 3j str3);通過Xml文件控制測試用例是一次性執行還是單個執行,并可以控制測試用例執行的順序,xml文件如下圖:com. Login,rname=l,testl/name=l

14、,test2/name=l,com. Login,rname=l,testl/name=l,test2/name=l,test3/name=l,test41,/name=l,test5/name=l,test61,/在xml文件完成后,需要書寫一個主函數來控制xml文件的執行,并制定執行完 成后測試結果的輸出路徑,如下圖所示public static void main(String args) fTest NIG testN:G=new TestNH5() j/testNG.setUseDefaultListeners(false);/HTHLReporter cp=n剝 HTTlMLRep

15、orterf);/testNG.addlListenerfcB:.) JSystem se tProp e rty (orgBunco mmon s . report ngB t it leLogin Test Re port er ) jList list=new ArrayList()jlist add(,pC : User5vrvworkspacetestTng+File. separator+,Bsrc/CQm,B+File . separa testNG.setTestSuites(list);/File file=new File (1BC : test Wresult11);Fi

16、le file=new FilefC : UsersvrvworkspacetestTngtest -output11) jif(!file.exists()file.mkdirf)jtest NIG. setOutputDirectory (f ile - getAbsolutePath ();test NIG. run();|每次執行完成后,testNG會生成一個默認的測試報告(test-output),該報告的路徑可自行指定j 曰 testTng J RE System Library JavaSE-1.7* TestN G或 Referenced Libraries build.xml

17、圖Login.xls用瀏覽器打開test-output下的index.html,可以看到該測試報告,如下圖 所示Test results1 suite com.Login com.LoginsuiteInfoCAUsers vTvworkspace testTng src comconfigljcmlsuiteInfoCAUsers vTvworkspace testTng src comconfigljcml1 tesE0 groupsTimesReporter outputIgnored methodsChronological viewResults. 6 methods. 6 Resu

18、lts. 6 methods. 6 passed Passed methods (hide) (show)C:UsersvrvworkspacetestTngsrccomconfigl.xml12 3 4 5 6 rrL t L rrL bL rru s s s s s s e e e e e e UL LL UL LL UL UL include include include include include include /classes name=wtestl/ name=wtest2/ name=wtest3/ name=resr4/ name=wt;esc5/ name=nt-es

19、t6/利用testNG+jxl直接將測試結果輸入到excel測試用例中,先導入jxl.Jar包,然后封裝一個控制excel操作的方法To Ecx Writepublic 匚1目ssTo Ecx Write/private static final Writ able Font HE ADE R_FONT_STYLE = null;public void write (File filej String stringint nunij int numlj baolean str) try Workbook rwb = Workbook. getJiforfetioofe(file);File t

20、empfile = new F ile ( Sy st em. gre tProp e rty (u s e r. d ir11) + tempf ile . xls) j WritableWorkbook wb = Workbook.erecrtelitorfebooi|?(tempfilej rwb);WritableSheet ws = wwb.getSheet(string);ws. setColumnView(4Ji 10); / 世置礦宣WritableFont font=new Writ able Font (Writ able FontWrit able Font .BOLDf

21、 alsej Underline St yle.AUNDF/ILIjVF/Colour./IFD);Writ a bleC ellFormat cFormat = new WritableCellFormat(font);水平居中再表c Format setAlignment (Alignment . CENTRE)/史宜方向居中.對寺cFo rmat s etVert ic a lAlignme nt (V ertica lAlignme nt. CENTRE);/云址垣軍迎忍跳方空墓(寂從.是驅生一一世可以甘址M地百生)c Fo rmat s et Bo r d e r(j xl.form

22、at.Bor d e r. TOP. Bo rd e rLin e Style. THIN);在i*打實映c Fo rmat - s et Bo rd e r ( j xl. format. Bord er. RIGtfTt Bord e rLi n e Style . THIN);String 5trl=str+,lllj;Label label = new Labelfnumj numlj strljCFormat)j ws.addCell(label)j wwb.write();wwb.closef)j并在test中調用此方法,完成對excel測試用例結果的輸出Thread.sLeep(

23、10&0);(fflTestpublic void testlf) throws InterruptedException _ hcicilwn Mrl=unit, isWEBEleniEiTtEKimt (By 元日 Lwubmit);_tewwrite(new File(11 Login.xls11)j11 login11, 4j lt strl);H(fflTestpublic void test2() throws InterruptedException unit. clear (By. ( account);unit.己般曰丫.田誠”submit) jThread.sleep(10&0);boolean str2=unit. signfByxp

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
  • 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論