亚洲好骚综合-亚洲黄色录像-亚洲黄色网址-亚洲黄色网址大全-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
主站蜘蛛池模板: www.国产精品 | 激情六月综合 | 午夜寂寞影院在线观看 | 日日摸夜夜摸狠狠摸日日碰夜夜做 | 欧美成人三级网站在线观看 | 亚洲成a人片| 午夜爱爱影院 | 天天夜夜狠狠 | 久久九九色| 国产日韩精品欧美一区色 | 久久精品国产屋 | 国产高清视频 | 在线成年人视频 | 五月天伊人 | 丁香六月久久 | 韩国视频在线 | 麻豆乐园 | 五月婷婷影院 | 一个人看的视频www免费 | 小黄漫画激情四射在线观看 | 欧美一级亚洲一级 | 青青艹在线视频 | 午夜h| 人人爱人人做 | 久久久午夜影院 | 男女无遮挡毛片视频播放 | 免费无遮挡十八女禁污污网站 | 花蝴蝶亚洲一区二区三区 | 天天综合五月天 | 日韩欧美第一页 | 日本高清在线观看天码888 | 亚洲综合偷自成人网第页色 | 国产一区二区高清视频 | 一级免费黄色毛片 | 国产精品乱 | 日本三级s级在线播放 | 午夜看一级特黄a大片黑 | 91精品视频在线免费观看 | www.久久.com| 秋霞国产在线 | 国产一区亚洲二区 |