Noah
Noah

Reputation: 1687

Rescuing Selenium WebDriver exceptions inside cucumber Around statement

I'm using the ruby selenium webdriver with cucumber to run multiple browser tests. I have several steps where exceptions could be raised, and don't want to put a begin/rescue block around every step. I found cucumber's Around hook which should allow me to call all of my steps in one big block, and put a begin/rescue block around that. Unfortunately, when a selenium exception is raised, the block never receives the exception. I'm theorizing that cucumber, for whatever reason, has it's own begin/rescue block which gets triggered before mine. For rails there's a tag called @allow-resue that lets the exception pass, unfortunately this won't work for Selenium. Does anyone know a work-around?

Upvotes: 0

Views: 487

Answers (1)

Omar N
Omar N

Reputation: 61

Around hook won't help. At all. You need only look at 'around_hook.rb' 'execute' method definition:

def execute(*args, &continue)
  @timer.start
  @block.call(continue)
  Result::Unknown.new # Around hook does not know the result of the inner test steps
rescue Result::Raisable => exception
  exception.with_duration(@timer.duration)
rescue Exception => exception
  failed(exception)
end

So if it does not know the result of the inner test steps, then it definitely won't know of any exceptions ocurring in the rest of said steps.

P.S. I have the same question...

Upvotes: 0

Related Questions