Skip to content

Instantly share code, notes, and snippets.

@chrisroane
Created November 22, 2017 22:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisroane/0c1b286b6cdcee0f63ffa4b94a092f21 to your computer and use it in GitHub Desktop.
Save chrisroane/0c1b286b6cdcee0f63ffa4b94a092f21 to your computer and use it in GitHub Desktop.
<?php
/**
* @file
* Provides code to handle failures in circleci.
*/
use Behat\Behat\Hook\Scope\AfterStepScope;
use Behat\Mink\Driver\Selenium2Driver;
use Behat\MinkExtension\Context\RawMinkContext;
use Behat\Gherkin\Node\FeatureNode;
class ErrorHandlingContext extends RawMinkContext {
/**
* If there are errors on circleci, save a screenshot.
*
* @param AfterStepScope $event
* AfterStepScope event object.
*
* @AfterStep
*/
public function printLastResponseOnError(AfterStepScope $event) {
if (!$event->getTestResult()->isPassed()) {
$this->saveDebugScreenshot($event->getFeature());
}
}
/**
* Save an error screenshot.
*
* @param FeatureNode $feature
* FeatureNode feature object.
*
* @Then /^save screenshot$/
*/
public function saveDebugScreenshot(FeatureNode $feature) {
$driver = $this->getSession()->getDriver();
if (!$driver instanceof Selenium2Driver) {
return;
}
$filename = basename($feature->getFile()) . '_' . microtime(TRUE) . '.png';
$this->saveScreenshot($filename, '/tmp/behat_screenshots');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment