When saving a screenshot with Watir png is empty or 0kb

I use cucumber and watir-webdriver and try to take a screenshot if it fails. With the examples that I found, it technically works, but the created png files are empty or 0kb.

I tried chrome and firefox and I use win7 x64 system.

I put 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 make it actually capture what is on the screen?

+4
source share
2 answers

Try saving a screenshot with this:

 browser.screenshot.save 'screenshot.png' 

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

+4
source

I fixed this problem by updating the binary. To debug this, I 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

0
source

All Articles