I would like an automated web tests suite based on Selenium RC to take screenshots of pages when some errors are encountered. The test suite is a part of the continuous integration process and technically is executed by CruiseControl running as a Windows service.
The selenium.captureScreenshot()
method is called to trigger the actual screenshot. I've registered a JUnit RunListener
to call it on any test failure.
The problem is the screenshots are just blank files - PNG files totally black. The dimensions are 1440x900.
When manually running the same tests from Eclipse the screenshots are OK (althought they are screenshots of the whole desktop not the browser window, but that's a different story and a minor issue). So I guess the cause of the problem is the Selenium being run as a Windows service.
How can I have the screenshots of pages taken when exceptions in Selenium tests happen?
The software used:
To take a screenshot in Selenium, we use an interface called TakesScreenshot, which enables the Selenium WebDriver to capture a screenshot and store it in different ways. It has a got a method "getScreenshotAs() " which captures the screenshot and store it in the specified location.
TakeScreenShot is an interface that captures screenshots of the visible portion of the page. getScreenshotAs is a method which comes with the TakeScreenShot interface.
Selenium offers a lot of features and one of the important and useful feature is of taking a screenshot. In order to take a screenshot of webpage save_screenshot() method is used. save_screenshot method allows user to save the webpage as a png file.
Looks like there's a completely different answer. The Windows service (managed by TanukiSoftware Java Service Wrapper) was started with wrapper.ntservice.interactive
set to false
. Setting it to true
has helped. Eventually the screenshots contain real screen content.
Consult the wrapper.ntservice.interactive
for details. The analysis of the wrapper code leads to [SERVICE_INTERACTIVE_PROCESS
](http://msdn.microsoft.com/en-us/library/ms683502(VS.85).aspx) flag being set when starting the Windows service.
What browser are you running these tests in? If it's Firefox I'd recommend the captureEntirePageScreenshot to capture the entire canvas - not just what's in view (rather than the screen) and captureEntirePageScreenshotToString if you're working remotely and want to save the files locally.
Not sure if it will help with your issue, but as it uses an add-on to Firefox it might be worth a try.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With