Selenium簡介
Selenium是web應用的測試工具。
網址是:www.openqa.org/selenium/
Selenium可直接在瀏覽器中測試,就像真正的瀏覽器用戶一樣。
可以運行在Windows和Macintosh下的IE,Mozilla Firefox。
可用於:
- 瀏覽器兼容性測試
- 系統功能測試
如果是初次使用Selenium,最好從SeleniumIDE開始,而不是從Selenium Core,因爲Selenium IDE集成了Selenium Core的功能。
Selenium如何工作
Selenium通過javascript和iframe將自動測試引擎嵌入到瀏覽器中。
Selenium可工作在任何能夠運行javascript的瀏覽器。
不同類型的瀏覽器的javascript處理存在差異,Selenium盡最大可能支持各種瀏覽器。
Selenium Core
使用Selenium Core,需要部署到web服務器上,纔可以測試。
這說明,使用Selenium Core(使用純DHTML/JavaScript)不能編寫測試比如google.com。
因爲Selenium Core是純DHTML/JavaScript的,受到客戶端JavaScript的安全限制。
這是JavaScript安全需求。如果不能修改要測試的webserer,Selenium Core不是合適的測試工具。
需要使用Selenium IDE或者Selenium RC替代。
Selenium IDE
見:http://www.openqa.org/selenium-ide/
Selenium IDE是一個測試集成開發環境。
是Firefox插件,可記錄,編輯和調試測試。
Selenium IDE包括完成的Selenium Core,易於和快速記錄和運行測試。
Selenium IDE不只是錄製工具:是完整的IDE。
可以錄製,或者手工寫腳本。
Selenium RC
Selenium RC即Selenium Remote Control。
如果測試google,又不能在google網站上添加Selenium Core,可以使用Selenium RC。
Selenium RC提供了一個代理服務器,比如可以讓瀏覽器以爲是在執行http://www.google.com/selenium-server/MyTestSuite.html
To use the Selenium Server as a proxy, run your tests like this:
啓動Selenium RC,作爲代理服務器執行測試,類似:
- java -jar selenium-server.jar -htmlSuite "*firefox" "http://www.google.com" "c:\absolute\path\to\my\HTMLSuite.html" "c:\absolute\path\to\my\results.html"
程序運行後生成results.html,如果超時,程序退出,而且不生成results.html。