Handling exceptions on cucumber scenarios

空扰寡人 提交于 2019-12-10 10:57:24

问题


I'm suffering from selenium's awkward behavior for alert boxes described here. Until this is resolved I need to rescue from Selenium::WebDriver::Error::UnhandledAlertError.

This is easily done when I've created the step where the exception originates: I plop in a rescue block and it works fine.

But what if the step is an existing one that I want to rescue from, in this case, checking a checkbox? I can't do anything at this level--can I?--so I thought adding a tag to the scenario and an around hook like the following would work, but it doesn't:

Around('@handle_alert_boxes') do |scenario, block| do
  begin
    block.call
  rescue Selenium::WebDriver::Error::UnhandledAlertError
    puts "It's OK!"
  end
end

I also tried cucumber's @allow-rescue tag, but it appears this only works when handling exceptions external to cucumber (like Rails) but not internal (like its driver--selenium).

Is there a way to handle this without creating a new step with a rescue block? That doesn't feel right and it will pollute my cucumber's vernacular.

来源:https://stackoverflow.com/questions/12787032/handling-exceptions-on-cucumber-scenarios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!