Tuesday 17 September 2013

Turn specific error into a failure in ruby Test::Unit

Turn specific error into a failure in ruby Test::Unit

I would like a way to take an error generated within a specific test
method inside a Test::Unit::TestCase and turn it into a failure with a
more friendly generic message. I keep thinking this should be possible
with some inheritance but I can't quite get my head around it.
class CalenderTest001 < Test::Unit::TestCase
def testZoneCal001
Fixture.reset
$driver = Selenium::WebDriver.for :firefox
$driver.get "http://myTestSite.com/"
$driver.find_element(:id, "IDthrowsAnError").click
end
end
The effect I would like is to have the entire thing wrapped in a begin
rescue end block with the rescue block looking something like this.
rescue Selenium::WebDriver::Error::NoSuchElementError => e
#mark this test as a failure not an error

No comments:

Post a Comment