Skip to content

Instantly share code, notes, and snippets.

@jmauerhan
Created June 2, 2015 17:38
Show Gist options
  • Save jmauerhan/19a13e9c277e7242a25f to your computer and use it in GitHub Desktop.
Save jmauerhan/19a13e9c277e7242a25f to your computer and use it in GitHub Desktop.
An AfterScenario function for behat that takes and saves a screenshot
<?php
/** @AfterScenario */
public function after($event)
{
if($event->getResult() == Event\StepEvent::FAILED)
{
$imagePathPrefix = 'http://mysite.local';
errorImagesDir = '/';
$imageData = $this->getSession()->getDriver()->getScreenshot();
$imagePath = $errorImagesDir . time() . '.png';
file_put_contents($imagePath, $imageData);
$imageUrl = $imagePathPrefix . $imagePath;
$this->printDebug($imageUrl . PHP_EOL);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment