亚洲好骚综合-亚洲黄色录像-亚洲黄色网址-亚洲黄色网址大全-99久久99久久-99久久99久久精品国产

您的位置:軟件測試 > 開源軟件測試 > 開源功能測試工具 > Selenium
利用Selenium自動化web測試
作者:網絡轉載 發布時間:[ 2016/6/15 16:19:26 ] 推薦標簽:Selenium 功能測試 自動化測試

  清單 4. 自動化選擇的 RC 代碼
  //click on the date field by id you defined;
  selenium.clickAt("dateBox","");
  //wait for the drop down date box by id;
  selenium.waitForCondition("selenium.isElementPresent("widget_dateBox_dropdown")",
  "2000");
  //click previous year 2008;
  selenium.clickAt("//span[contains(@class,'dijitCalendarPreviousYear')]", "");
  //click on the month increase;
  //previous month would contains  ‘dijitCalendarIncrease’.
  selenium.clickAt("//img[contains(@class,'dijitCalendarIncrease')]","");
  //click on the date such as 28 of current month; If you do not specify
  //the td with the attribute of current month class, it will click
  on the //first 28 of previous month;
  selenium.click("//td[contains(@class,'dijitCalendarCurrentMonth')]/span[text()='28']");
  如本例所示,Dojo 應用程序不能通過簡單的 IDE 記錄進行測試。這些腳本有可能不能通過測試。腳本中有一些丟失的操作,或者操作并不真正工作。腳本應該調整成能夠在 IDE 和 RC 中順利地執行。對于復雜的 Dojo 小部件,一種可能的解決方案是使用 runScript(String) 函數,因為 Selenium 對 JavaScript 提供很好的支持。清單 5 提供一個 JavaScript 語句來模擬組合框選擇。
  清單 5. 運行 JavaScript 語句在組合框上進行選擇
  selenium.runScript("dijit.byId("offeringType").setValue("Stack(SWG)");");
  如何利用 Ant 構建 Selenium 測試
  諸如 Ant 這樣的集成工具可以方便地構建 Selenium 測試和順暢地運行測試用例,無需單獨啟動 Selenium 服務器。如果 Selenium 測試由 TestNG 驅動,那么定義清單 6 所示 TestNG Ant 任務。清單 6 中假設 classpath 是 TestNG.jar 文件的文件路徑。
  清單 6. TestNG Ant 任務
  <taskdef resource="testngtasks" classpath="testng.jar"/>      
  主要的目標是啟動服務器、運行測試,然后停止服務器。這些任務按照 bulid.xml 中定義的順序實現在清單 7 中。
  清單 7. 啟動服務器、運行測試用例并停止服務器的 Ant 任務
  <target name="run_test" description="start,run and stop" depends="dist">
  <parallel>
  <antcall target="start-server" />
  <sequential>
  <echo taskname="waitfor" message="Waitforproxy server launch" />
  <waitfor maxwait="2" maxwaitunit="minute" checkevery="100">
  <http url="http://localhost:4444/selenium-server/driver/?cmd=testComplete" />
  </waitfor>
  <antcall target="runTestNG" />
  <antcall target="stop-server" />
  </sequential>
  </parallel>
  </target>
  代碼更可取的地方是使用 waitfor 任務來測試 Selenium 服務器是否已成功啟動,而不是暫停一段固定的時間。如果 URL http://localhost:4444/selenium-server/driver/?cmd=testComplete 可用,意味著 Selenium 已經成功啟動。在清單 7 中,它多等待兩分鐘,并且每 100 毫秒在本地主機上檢查一次 Selenium 服務器,以提供完整的 URL。
  start-server 任務的詳細內容定義在清單 8 中。Firefox profile 模板位置和其他參數可以指定在標記 <arg> 中。
  清單 8. 詳細的啟動服務器的 Ant 任務
  <target name="start-server">
  <java jar="lib/selenium-server.jar" fork="true">
  <arg line="-firefoxProfileTemplate ${selenium}/profile/" />
  </java>
  </target>
  runTestNG 任務的詳細內容定義在清單 9 中。testng 任務的常用屬性包括 outputDir 和 xmlfileset。屬性 outputDir 用于設置輸出報告位置。屬性 xmlfileset 用于包含啟動 XML 文件。更多選項請參考 TestNG 正式網站。
  清單 9. 運行測試用例的 Ant 任務
  <target name="runTestNG">
  <testng outputDir="${testng.report.dir}" sourcedir="${build}"
  classpathref="run.cp" haltOnfailure="true">
  <xmlfileset dir="${build}" includes="testng.xml" />
  </testng>
  </target>
  stop-server 任務的詳細內容定義在清單 10 中。
  清單 10. 停止 Selenium 服務器的 Ant 任務
  <target name="stop-server">
  <get taskname="selenium-shutdown"
  src="http://localhost:4444/selenium-server/driver/?cmd=shutDown" ignoreerrors="true" />
  <echo taskname="selenium-shutdown" message=" Errors during shutdown are expected" />
  </target>
  上面列出了關鍵任務。將它們組合到您的構建文件,以便利用 Ant 完成良好集成的測試。
  如何支持測試 HTTPS 網站
  隨著互聯網日益強調信息安全,越來越多的 web 應用程序在使用 SSL 身份認證。Selenium IDE 默認支持 HTTPS,但是 Selenium RC 不是這樣的。Internet Explorer 和 Firefox 中的解決方案各不相同。
  對于 IE,在 setup 目錄下的 SSL 支持文件夾中在安裝一個證書。如果使用的版本早于 Selenium-RC 1.0 beta 2,請使用 *iehta 運行模式,對于 Selenium-RC 1.0 beta 2 或更晚的版本,使用 *iexplore 運行模式。
  如果測試 HTTPS 網站時出現一個如下所示的安全警告,那么單擊 View Certificate 并安裝 HTTPS 網站的證書。如果繼續彈出警告,那么考慮在 IE 中進行配置。打開 Tool > Internet Options > Advanced,并取消選擇 security 分類下的 Warn about invalid site certificates 和 Check for publisher's certificate revocation。
上一頁12345下一頁
軟件測試工具 | 聯系我們 | 投訴建議 | 誠聘英才 | 申請使用列表 | 網站地圖
滬ICP備07036474 2003-2017 版權所有 上海澤眾軟件科技有限公司 Shanghai ZeZhong Software Co.,Ltd
主站蜘蛛池模板: 日韩在线视频中文字幕 | 亚洲欧美一区二区三区在线 | 日本中文在线播放 | 九九全国免费视频 | 不卡视频在线播放 | 欧美日韩一区二区在线视频 | 香蕉视频首页 | 国产精品亚洲专区在线观看 | 国产亚洲一区二区三区不卡 | 国产精品亚洲片在线观看不卡 | 国产日韩欧美亚洲 | 免费又黄又硬又大爽日本 | 日韩欧美国产成人 | 欧美经典成人在观看线视频 | 一级特黄aaaaaa大片 | 天天干天天做天天射 | 色迷迷网免费站视频在线观看 | 久久亚洲私人国产精品 | 天天操人人射 | 在线观看国产日本 | 91一级片| 日韩欧美在 | 97免费在线 | 国产伦精品一区二区三区 | 国产精品久久久久久久久久一区 | 大陆黄色网 | 日本xxxx色视频在线观看免 | 午夜精品国产爱在线观看不卡 | 欧美成人免费观看久久 | 中国一级特黄aa毛片大片 | 久久黄色毛片 | 天天摸日日添狠狠添婷婷 | 日韩中文字幕精品一区在线 | 成年人网址在线观看 | 8x福利精品第一福利视频导航 | 91视频一区二区 | 欧美日韩亚洲成人 | 看全色黄大色黄女片18 | 国产一区二区精品久 | 99爱在线精品视频免费观看9 | 黑丝套图 |