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

See here for a pretty decent into to ruby exception handling 
http://www.skorks.com/2009/09/ruby-exceptions-and-exception-handling/  

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

 

-- 
-- 
Before posting, please read http://watir.com/support. In short: search before 
you ask, be nice.

watir-general@googlegroups.com
http://groups.google.com/group/watir-general
watir-general+unsubscr...@googlegroups.com

--- 
You received this message because you are subscribed to the Google Groups 
"Watir General" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to watir-general+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to