Search code examples
rubycucumberscreenshotwatirwatir-webdriver

when saving a screenshot with Watir the png is empty or 0kb


I am using cucumber and watir-webdriver and am trying to take a screenshot on failure. With the examples I found, it is technically working but the png files that are created are blank or 0kb in size.

I have tried chrome and firefox and am using a win7 x64 system.

I am putting the following in my env.rb file.

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.driver.save_screenshot(screenshot)
   embed screenshot, 'image/png'
 end
end

How can I get it to actually capture what is on the screen?


Solution

  • Try saving the screen shot with this:

    browser.screenshot.save 'screenshot.png'
    

    More information: http://watirwebdriver.com/screenshots/