Skip to content

Instantly share code, notes, and snippets.

@mustafaileri
Last active January 30, 2017 08:59
Show Gist options
  • Save mustafaileri/2c85d83347933020695c075abac4b0bc to your computer and use it in GitHub Desktop.
Save mustafaileri/2c85d83347933020695c075abac4b0bc to your computer and use it in GitHub Desktop.
save screenshot and document on behat test fail
<?php
use Behat\MinkExtension\Context\MinkContext;
class BaseContext extends MinkContext
{
...
...
/*
* @AfterStep
*/
private function logErrors(AfterStepScope $event)
{
$driver = $this->getSession()->getDriver();
$screenshot = $driver->getWebDriverSession()->screenshot();
$fileName = $file = mb_ereg_replace("([^\w\s\d\-_~,;\[\]\(\).])", '', $event->getStep()->getText());
$content = $this->getSession()->getPage()->getContent();
if ($event->getTestResult()->getResultCode() == TestResult::FAILED) {
$this->saveDocument($fileName, $content);
$thi->saveScreenShot($fileName, $screenshot);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment