watir-webdriver black screenshots

强颜欢笑 提交于 2020-01-03 13:30:13

问题


I'm using watir-webdriver to navigate around my website and grab screenshots in different browsers.

Sometimes the screenshots taken in IE turn out the right size, but colored entirely black. The firefox tests that get run at the same time look fine.

browser.driver.save_screenshot(screenshot_dir)

Once I remote desktop to the computer running the tests the IE screenshots look okay again. A little bit after leaving remote desktop the IE screenshots go black again.

I'm running these tests on a instance of Windows Server running on ec2.


回答1:


Based on your comment that remotely accessing the machine resolves the problem for a little while... disable the screensaver on that box. I'm not sure how (if at all) the screenshot functions on IE and FF differ, but it's worth the time it would take to test the change.

Edit: I still feel like it's windows/power setting related as you logging into the box appears to have an effect, but I don't know what else specifically that could be. I tried a programmatic approach below vvv.




回答2:


From what you are saying, it sounds like the Windows system is automatically locking, like it should. This would explain why screenshots work fine when you remote in, and then go to black several minutes later when the screensaver kicks in and locks your system.

If the Windows system is locked, screenshots are blacked out. This is a Windows security feature.

I would be curious to know if FF really does do screen captures on a locked system.




回答3:


Here's the code I'm using to capture screenshots (Watir-Webdriver, Cucumber). I use remote Windows XP VMs for my test boxes, and have not encountered the issue using Firefox or Internet Explorer.

We did find that when you view the log with the embedded screenshot, it does not seem to work in IE - so you have to use Firefox for viewing. It's base64, so there doesn't seem to be a logical reason for this.

After do |scenario|
   if scenario.failed?
      encoded_img = @browser.driver.screenshot_as(:base64)
      embed("data:image/png;base64,#{encoded_img}", 'image/png') 
   end #
end


来源:https://stackoverflow.com/questions/7970401/watir-webdriver-black-screenshots

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!