Skip to content

Instantly share code, notes, and snippets.

@revagomes
Forked from jhedstrom/FeatureContext.php
Created May 22, 2022 17:22
Show Gist options
  • Save revagomes/2814e9dbcf87bf8e6044debc660ae378 to your computer and use it in GitHub Desktop.
Save revagomes/2814e9dbcf87bf8e6044debc660ae378 to your computer and use it in GitHub Desktop.
Behat Selenium driver screenshot
<?php
/**
* @AfterStep
*/
public function takeScreenShotAfterFailedStep(AfterStepScope $scope) {
if (99 === $scope->getTestResult()->getResultCode()) {
$driver = $this->getSession()->getDriver();
if (!($driver instanceof Selenium2Driver)) {
return;
}
file_put_contents('/path/to/screenshots/filename.png', $this->getSession()->getDriver()->getScreenshot());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment