Skip to content

Instantly share code, notes, and snippets.

@michalochman
Created July 25, 2012 08:53
Show Gist options
  • Star 19 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save michalochman/3175175 to your computer and use it in GitHub Desktop.
Save michalochman/3175175 to your computer and use it in GitHub Desktop.
Take screenshot with Behat/Mink after failed step
/**
* Take screenshot when step fails.
* Works only with Selenium2Driver.
*
* @AfterStep
*/
public function takeScreenshotAfterFailedStep($event)
{
if (4 === $event->getResult()) {
$driver = $this->getSession()->getDriver();
if (!($driver instanceof Selenium2Driver)) {
//throw new UnsupportedDriverActionException('Taking screenshots is not supported by %s, use Selenium2Driver instead.', $driver);
return;
}
$screenshot = $driver->wdSession->screenshot();
file_put_contents('/tmp/test.png', base64_decode($screenshot));
}
}
@AlexSkrypnyk
Copy link

Another dedicated extension with support for Mink (Goutte) and Selenium screenshots
https://github.com/integratedexperts/behat-screenshot

@forceedge01
Copy link

Another extension that gives more than just a screenshot with minimal setup! https://github.com/forceedge01/behat-fail-aid

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment