Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to continue a Cucumber step after an unpredictable modal dialog pops up?

I have a Ruby and Watir-webdriver -based Cucumber test suite for a web application and that web application relies on a service to provide some of its data through a sort of search.

There's a lot of data in this external service and sometimes the search will take a long time. When this happens, a modal dialog pops up on the web application. We really can't predict when that will happen and it isn't very practical to throw in browser.alert.ok calls throughout all of my step definitions.

So far, we've been handling the issue with an After hook that simply drops and restarts the browser. This saves the test suite during our full runs, but it doesn't help the test in question.

Long story short, I'd like a way to simply catch the Selenium::WebDriver::Error::UnhandledAlertError exception (the associated message is "Modal dialog present") whenever it pops up in a step, recognize what's happening (probably by matching the exception type and text, then matching the modal dialog text), and continue the step from the line we were at when the exception caused the interruption. Any thoughts?

like image 519
Kyle Oliveira Avatar asked Dec 06 '25 14:12

Kyle Oliveira


1 Answers

I think you just need something like:

step /^some code$/ do 
  begin
    #Your actual step
  end
  rescue
    browser.alert.ok
    next
end
like image 50
mvndaai Avatar answered Dec 08 '25 06:12

mvndaai



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!