Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selenium run as a Windows service to take screenshots on errors

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:

  • Windows 2003 Server
  • Selenium 1.0.1
like image 402
Grzegorz Oledzki Avatar asked Aug 11 '09 12:08

Grzegorz Oledzki


People also ask

How did you capture screenshots in Selenium?

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.

Is taking screenshot an interface or class?

TakeScreenShot is an interface that captures screenshots of the visible portion of the page. getScreenshotAs is a method which comes with the TakeScreenShot interface.

How do I take a screenshot using Selenium Python?

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.


2 Answers

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.

like image 147
Grzegorz Oledzki Avatar answered Oct 08 '22 13:10

Grzegorz Oledzki


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.

like image 44
Dave Hunt Avatar answered Oct 08 '22 13:10

Dave Hunt