WatirMILY: 宋體">是一個使用Ruby實現的開源Web自動化測試框架,相對于那些龐大的商業工具來說,它很小巧,也很靈活,提供的功能也足夠用。最近抽時間試用了一下,感覺還不錯,準備下一步在公司推廣使用。
因為Watir的網站上用戶手冊、示例代碼以及FAQ都維護的不錯,所以已有的東西我就不重復了,在這里簡單介紹一下,如果同行們有興趣,可以一起研究一下。
1. 腳本示例
先丟一段腳本給大家看看使用Watir來書寫腳本是多么的方便。下面的例子是Watir自帶的一段測試Google的搜索功能的腳本,不過我只保留了最主要的部分,以使它看起來更簡潔一些:
require 'watir' # the watir controller
# open the IE browser
ie = Watir::IE.new
# Step 1: go to the test site: http://www.google.com
ie.goto (http://www.google.com)
# Step 2: enter 'pickaxe' in the search text field
ie.text_field(:name, "q").set("pickaxe") # q is the name of the search field
# Step 3: click the 'Google Search' button
ie.button(:name, "btnG").click # "btnG" is the name of the Search button
# Actual Result: Check that the 'Programming Ruby' link appears on the results page
if ie.contains_text("Programming Ruby")
puts "Test Passed. Found the test string: 'Programming Ruby'. Actual Results match Expected Results."
else
puts "Test Failed! Could not find: 'Programming Ruby'"
end
# End of test: Google search
這段腳本要做的事情是打開Google的主頁,然后在Google唯一的那個文本框內輸入“pickaxe”這個字符串,然后按下“Google搜索”按鈕,之后驗證搜索結果的頁面中是否包含了“Programming Ruby”這個字符串,并根據結果使用puts函數在屏幕上打印不同的信息。腳本中“#”后面的綠色部分是注釋的內容。簡單嗎?說實話要比那些商業工具錄制的腳本還要簡潔和簡單。
2. 所需要的環境
Ruby :因為是使用Ruby實現的,腳本也是Ruby的腳本,所以需要在本機安裝Ruby?梢渣c擊這里下載。根據文檔中說的,最好選擇Ruby 1.8.2-14或者更高的版本,我安裝的是Ruby 1.8.2-15 Stable Release。
Watir :可以點擊從這里下載,我下載的是Watir 1.4,是一個.zip文件,解壓縮以后執行install.rb就可以了,具體的安裝和配置請參見Watir用戶手冊。不要怕,雖然是英文的,但是很簡單。
WINDOWS 2000或XP + IE 5.5以上版本:根據Watir網站上的描述,這是他們目前支持的環境。
文章來源于領測軟件測試網 http://www.kjueaiud.com/