Alex Mandoli
Alex Mandoli

Reputation: 1

Watir-Webdriver : take screenshot upon error/exception/fail. How to?

I am new to Watir-Webdriver. I have written a function to take the screenshot and it works fine. My problem is I need to call the method, upon any error/exception or fail happening during my testcase execution. I have googled it and couldn't find anything related. I have tried rescue block but it doesn't work for me. Any help is appreciated. Thanks, Alex

Upvotes: 0

Views: 735

Answers (1)

Dave McNulla
Dave McNulla

Reputation: 2016

Alister Scott has this about getting screenshots on WatirMelon when using cucumber:

After do |scenario|
  if scenario.failed?
    Dir::mkdir('screenshots') if not File.directory?('screenshots')
    screenshot = "./screenshots/FAILED_#{scenario.name.gsub(' ','_').gsub(/[^0-9A-Za-z_]/, '')}.png"
    Browser::BROWSER.driver.save_screenshot(screenshot)
    embed screenshot, 'image/png'
  end
end

Upvotes: 3

Related Questions