public function FeatureContext::takeScreenshotAfterFailedStep in Acquia Lift Connector 7.2
Same name and namespace in other branches
- 7 behat-tests/features/bootstrap/FeatureContext.php \FeatureContext::takeScreenshotAfterFailedStep()
Take screenshot when step fails. Works only with Selenium2Driver.
@AfterStep
File
- behat-tests/
features/ bootstrap/ FeatureContext.php, line 139
Class
- FeatureContext
- Defines application features from the specific context.
Code
public function takeScreenshotAfterFailedStep(AfterStepScope $scope) {
if (!$scope
->getTestResult()
->isPassed()) {
$driver = $this
->getSession()
->getDriver();
if (!$driver instanceof Selenium2Driver) {
//throw new UnsupportedDriverActionException('Taking screenshots is not supported by %s, use Selenium2Driver instead.', $driver);
return;
}
$step = $scope
->getStep();
$step_line = $step
->getLine();
$temp_path = $this
->getContextParameter('temp_path');
$filename = $temp_path . '/stepAtLine' . $step_line . '.png';
$screenshot = $driver
->getWebDriverSession()
->screenshot();
file_put_contents($filename, base64_decode($screenshot));
echo "Saved Screenshot To {$filename} \n";
$filename = $temp_path . '/stepAtLine' . $step_line . '.html';
$source = $driver
->getWebDriverSession()
->source();
file_put_contents($filename, $source);
echo "Saved Source To {$filename}\n";
}
}