-
-
Save jk/6422163 to your computer and use it in GitHub Desktop.
Take screenshots with Behat + Mink + Selenium2 Stack when a step fails. CAUTION: Work in progress
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 | |
use Behat\Behat\Event\StepEvent; | |
use Behat\Gherkin\Node\StepNode, | |
Behat\Gherkin\Node\ScenarioNode, | |
Behat\Gherkin\Node\FeatureNode; | |
use Behat\Mink\Driver\Selenium2Driver; | |
/** | |
* Take screenshot when step fails. | |
* Works only with Selenium2Driver. | |
* | |
* @AfterStep | |
*/ | |
public function takeScreenshotAfterFailedStep(StepEvent $event) | |
{ | |
if (StepEvent::FAILED === $event->getResult()) { | |
$driver = $this->getSession()->getDriver(); | |
// var_dump($step); | |
if (!($driver instanceof Selenium2Driver)) { | |
// throw new UnsupportedDriverActionException('Taking screenshots is not supported by %s, use Selenium2Driver instead.', $driver); | |
return; | |
} | |
$stepNode = $event->getStep(); | |
$scenarioNode = $stepNode->getParent(); | |
$featureNode = $scenarioNode->getFeature(); | |
// $title = ['step' => $stepNode->getText(), 'scenario' => $scenarioNode->getTitle(), 'feature' => $featureNode->getTitle().": ".$featureNode->getDescription()]; | |
// var_dump($title); | |
$screenshot = $driver->getWebDriverSession()->screenshot(); | |
file_put_contents('/tmp/test.png', base64_decode($screenshot)); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment