On Friday, May 17, 2013 3:13:58 AM UTC-7, LuisE wrote:
Hello, I use "@browser.screenshot.save file" for when I have a problem, but when I use it and I have a Timeout Exception it doesn't work well, because it was waiting for page load totally(This page never load because It has a problem). How can I do for It doesn't wait and capture a snapshoot?
Best Regards
If you are trying to do this inline in your code then wrap the thing you expect to sometimes fail with exception handling, and have the screenshot as part of the actions to take when it fails
What I'd do is something along these lines
begin
#code you think might fail due to timeout
rescue
#code to take screenshot
raise "timeout trying to load page xxxx" #presumes we still want the test to fail at this point
end
A better way however is if you are using a framework like cucumber, which allows you to define things to happen after every test. You can put code there that takes specific actions if the test failed, such as taking a screenshot and embedding it in the html report generated by the framework EG
#I use cucumber, this is from my env.rb file
After do |scenario|
if scenario.failed?
screenshot = "./FAILED_#{scenario.name.gsub(' ','_').gsub(/[^0-9A-Za-z_]/, '')}.png"
@browser.driver.save_screenshot(screenshot)
encoded_img = @browser.driver.screenshot_as(:base64)
embed("data:image/png;base64,#{encoded_img}",'image/png')
end
end