taking a screenshot with phpunit and selenium RC

PHPUnit has built in support for taking a screenshot with Selenium and storing it locally (as in, on the server that is running the firefox instance)

This doesn’t work well when you’re running selenium RC, because you won’t know what server firefox eventually runs on.

Fortunately, PHPUnit also implements captureEntirePageScreenshotToString(), which will return a base64-encoded PNG that you can decode and store locally (for example, to provide to Jenkins as an artifact)

In this example, I want to capture the screenshot when the test ends, or when it fails.

You can implement this code elsewhere if you wanted to take screenshots on failure only, after each test, etc…