2

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.

4

0 回答 0