Question

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?

Was it helpful?

Solution 2

I encountered a similar problem in my project, where I used to get random fatal error dialogs.

The approach I followed is to handle the dialog in AfterStep hook. Since in cucumber every step is atomic, after every step I verify whether the fatal error dialog is present. If it is there then click OK and proceed with the execution.

Hope this helps for you.

OTHER TIPS

I think you just need something like:

step /^some code$/ do 
  begin
    #Your actual step
  end
  rescue
    browser.alert.ok
    next
end
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top