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.
require_once 'PHPUnit/Extensions/SeleniumTestCase.php';
class yourTest extends PHPUnit_Extensions_SeleniumTestCase {
//// rest of your tests here
/**
* On teardown, capture a screenshot.
*/
public function tearDown() {
file_put_contents('result.png', base64_decode($this->captureEntirePageScreenshotToString()));
}
}
You can implement this code elsewhere if you wanted to take screenshots on failure only, after each test, etc…