自动化测试与Rails视图开发全解析
1. 利用Selenium和Webrat进行自动化测试
在自动化测试中,当Webrat的API无法满足需求时,我们可以借助selenium - client API来获得更多灵活性。selenium - client API有大约十几种以“is_”开头的方法,这些方法用于检查浏览器状态并返回布尔值。例如:
Then /^the first photo should be first in the album$/ do
wait_for do
selenium.is_ordered(
"id=#{dom_id(@photo1)}",
"id=#{dom_id(@photo2)}"
).should be_true
end
end
此外,我们还可以在浏览器中执行任意JavaScript代码,根据JavaScript可访问的内容编写测试步骤。比如,若网站通过 ajax.requestCounter 记录页面触发的Ajax请求数量,我们可以这样编写步骤定义:
Then /^three AJAX requests should have executed$/ do
ajax_requests = selenium.get_eval(<<-JS)
var currentWindow = selenium.browserbot.getCurrentWindow();
currentWindow.a
超级会员免费看
订阅专栏 解锁全文
4

被折叠的 条评论
为什么被折叠?



