Bar*_*cha 15 ruby-on-rails cucumber
我正在尝试使用Cucumber on Rails测试JS确认对话框.我有一个window.onbeforeunload事件处理程序,如果你试图离开页面但是我不知道如何测试它会提示你一个确认对话框,任何人都知道如何做到这一点?
您可以使用硒的各种功能来捕获警报/确认.它们不能直接用于webrat selenium实现,但是当使用webrat时,config.mode = :selenium它们可以按如下方式使用:
Then /^I should see a JS alert$/ do
selenium.is_alert_present.should be_true
end
# or
Then /^I should see a "Are you sure?" JS confirm dialog$/ do
selenium.get_alert.should eql("Are you sure?")
end
# you can also click the OK/Cancel buttons on confirm boxes with
selenium.chooseOkOnNextConfirmation();
#and
selenium.chooseCancelOnNextConfirmation();
Run Code Online (Sandbox Code Playgroud)
可能没有最好的测试,但给你一个想法.内部selenium覆盖JS的alert()和confirm()函数,因此它可以捕获这些信息.
您可以在selenium faq或gem服务器上找到更多文档
| 归档时间: |
|
| 查看次数: |
4241 次 |
| 最近记录: |