Created
November 22, 2017 22:15
-
-
Save chrisroane/0c1b286b6cdcee0f63ffa4b94a092f21 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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