开源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 |