Josh Lesch
Josh Lesch

Reputation: 405

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?

Upvotes: 4

Views: 1395

Answers (2)

codesman
codesman

Reputation: 41

I fixed this problem by updating my chromedriver binary file. To debug this I have used: browser.screenshot.save('your_file'.png) in the step, where I got this error: org.openqa.selenium.WebDriverException: unknown error: cannot get automation extension

Upvotes: 0

Željko Filipin
Željko Filipin

Reputation: 57282

Try saving the screen shot with this:

browser.screenshot.save 'screenshot.png'

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

Upvotes: 4

Related Questions