Php – Selenium RC sending blank screenshots through (winxp/winserver)

PHPscreenshotseleniumselenium-rc

I'm trying to set up my virtual (xen) win xp instances, a dedicated windows server, and a dedicated windows xp desktop pc for web app UI testing, using selenium-rc and the selenium PHP API from pear (the php script running the tests sits on its app server, on the same local network as the remote-controlled windowses).

Everything has worked out great so far, except i am unable to get a screenshot from selenium RC – they are all blank (gray) after base64_decode(); (without that, they dont even open).

Despite os x preview displays them as gray, i'm pretty sure they are actually transparent or have some kind of other corruption because Photoshop wont open them at all. (and they weigh 0.7k) The unix "file" command however recognizes them correctly as "PNG image, 1440 x 900, 8-bit/color RGB, non-interlaced" – 1440 x 900 is the resolution of my Mac, connected to the windows systems through remote desktop.

I'm running the selenium rc directly (ie java -jar selenium-server.jar), not as a service. The symptoms are the same accross all my windows test systems.

My Selenium version is 1.0.1, here's the snippet that tries to get the screenshot:

$this->selenium->windowMaximize();
$screenshot = $this->selenium->captureScreenshotToString();

I'm using the latest Testing_Selenium pear package.
I realize there is a question here dealing with a similar issue, but i'm not using a service wrapper nor i can afford to introduce this complexity (but do let me know if you think that's a mistake)

thanks & regards,
Andras

ps: i'm cross posting this to several forums in a desperate attempt to get some imput – apologies if that upsets you 🙂

edit: selenium rc console says

16:38:24.562 INFO – Got result: [base64 encoded PNG] on session a5304a287eb24402
8c8c843b294bf98f
java.net.SocketException: Software caused connection abort: socket write error
at java.net.SocketOutputStream.socketWrite0(Native Method)
at java.net.SocketOutputStream.socketWrite(Unknown Source)
at java.net.SocketOutputStream.write(Unknown Source)
at org.mortbay.http.ChunkingOutputStream.bypassWrite(ChunkingOutputStrea
m.java:151)
at org.mortbay.http.BufferedOutputStream.write(BufferedOutputStream.java
:142)
at org.mortbay.http.HttpOutputStream.write(HttpOutputStream.java:423)
at org.mortbay.http.HttpOutputStream.write(HttpOutputStream.java:414)
at org.openqa.selenium.server.SeleniumDriverResourceHandler.handleComman
dRequest(SeleniumDriverResourceHandler.java:370)
at org.openqa.selenium.server.SeleniumDriverResourceHandler.handle(Selen
iumDriverResourceHandler.java:125)
at org.mortbay.http.HttpContext.handle(HttpContext.java:1530)
at org.mortbay.http.HttpContext.handle(HttpContext.java:1482)
at org.mortbay.http.HttpServer.service(HttpServer.java:909)
at org.mortbay.http.HttpConnection.service(HttpConnection.java:820)
at org.mortbay.http.HttpConnection.handleNext(HttpConnection.java:986)
at org.mortbay.http.HttpConnection.handle(HttpConnection.java:837)
at org.mortbay.http.SocketListener.handleConnection(SocketListener.java:
245)
at org.mortbay.util.ThreadedServer.handle(ThreadedServer.java:357)
at org.mortbay.util.ThreadPool$PoolThread.run(ThreadPool.java:534)

for all screen captures.

Best Answer

When there is no physical desktop (or remote desktop session), the Java process that runs Selenium RC will result in a black screenshot. Without knowing more info, this could be your problem.

As the creator of Selenium RC, I actually recommend against using the Windows Service entirely. Instead, do what we do at BrowserMob, which provides free monitoring and free load testing services, as well as a recently launch instant test tool that takes screenshots of your site from multiple locations.

What we do is launch everything from under the context of a VNC session. On Windows, configure VNC to launch a session upon startup. Then make sure the user auto-logs in. Then place a .bat file in Program Files->Startup that launches Selenium RC. It's kind of a pain, but it's the most reliable way I've found for ensuring that Selenium RC starts in an environment that supports screenshots, launching IE, interacting with native events, etc.

Good luck!