Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Save screenshot of a failed Behat step
* @AfterStep
public function takeScreenshotAfterFailedStep($event)
if ($event->getTestResult()->getResultCode() === \Behat\Testwork\Tester\Result\TestResult::FAILED) {
$driver = $this->getSession()->getDriver();
if ($driver instanceof \Behat\Mink\Driver\Selenium2Driver) {
$stepText = $event->getStep()->getText();
$fileName = preg_replace('#[^a-zA-Z0-9\._-]#', '', $stepText).'.png';
$filePath = sys_get_temp_dir();
$this->saveScreenshot($fileName, $filePath);
print "Screenshot for '{$stepText}' placed in ".$filePath.DIRECTORY_SEPARATOR.$fileName."\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.