I ended up using a modified version of @sectus' answer:
public function onNotSuccessfulTest(Exception $e) {
$file_name = '/' . date('Y-m-d_H-i-s') . ' ' . $this->getName() . '.png';
file_put_contents($this->screenshotPath . $file_name, base64_decode($this->captureEntirePageScreenshotToString()));
parent::onNotSuccessfulTest($e);
}
Although the conditional check in tearDown()
works fine, based on Extending phpunit error message, I decided to go with onNotSuccessfulTest()
as it seemed cleaner.
The filename could not accept colons :
, or I would get an error message from file_get_contents
: failed to open stream: Protocol error
The function currentScreenshot
also did not exist, so I ended up taking the screenshot in a different way according to http://www.devinzuczek.com/2011/08/taking-a-screenshot-with-phpunit-and-selenium-rc/.