Skip to content
This repository was archived by the owner on Apr 20, 2021. It is now read-only.

Commit f36b3b5

Browse files
blazareckisanpii
authored andcommitted
Don’t require @javascript to take screenshot
1 parent ae90d9b commit f36b3b5

1 file changed

Lines changed: 25 additions & 15 deletions

File tree

src/Context/DebugContext.php

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Behat\Gherkin\Node\StepNode;
66
use Behat\Behat\Hook\Scope\AfterStepScope;
7+
use Behat\Mink\Exception\UnsupportedDriverActionException;
78

89
class DebugContext extends BaseContext
910
{
@@ -48,22 +49,22 @@ public function iSaveAScreenshotIn($filename)
4849
*/
4950
public function failScreenshots(AfterStepScope $scope)
5051
{
51-
if (! $scope->getTestResult()->isPassed()) {
52-
$suiteName = urlencode(str_replace(' ', '_', $scope->getSuite()->getName()));
53-
$featureName = urlencode(str_replace(' ', '_', $scope->getFeature()->getTitle()));
54-
if ($this->getBackground($scope)) {
55-
$makeScreenshot = $scope->getFeature()->hasTag('javascript');
56-
$scenarioName = 'background';
57-
} else {
58-
$scenario = $this->getScenario($scope);
59-
$makeScreenshot = $scope->getFeature()->hasTag('javascript') || $scenario->hasTag('javascript');
60-
$scenarioName = urlencode(str_replace(' ', '_', $scenario->getTitle()));
61-
}
62-
if ($makeScreenshot) {
63-
$filename = sprintf('fail_%s_%s_%s_%s.png', time(), $suiteName, $featureName, $scenarioName);
64-
$this->saveScreenshot($filename, $this->screenshotDir);
65-
}
52+
if ($scope->getTestResult()->isPassed()) {
53+
return;
54+
}
55+
56+
$suiteName = urlencode(str_replace(' ', '_', $scope->getSuite()->getName()));
57+
$featureName = urlencode(str_replace(' ', '_', $scope->getFeature()->getTitle()));
58+
59+
if ($this->getBackground($scope)) {
60+
$scenarioName = 'background';
61+
} else {
62+
$scenario = $this->getScenario($scope);
63+
$scenarioName = urlencode(str_replace(' ', '_', $scenario->getTitle()));
6664
}
65+
66+
$filename = sprintf('fail_%s_%s_%s_%s.png', time(), $suiteName, $featureName, $scenarioName);
67+
$this->saveScreenshot($filename, $this->screenshotDir);
6768
}
6869

6970
/**
@@ -110,4 +111,13 @@ function (StepNode $step) {
110111

111112
return false;
112113
}
114+
115+
public function saveScreenshot($filename = null, $filepath = null)
116+
{
117+
try {
118+
parent::saveScreenshot($filename, $filepath);
119+
} catch (UnsupportedDriverActionException $e) {
120+
return;
121+
}
122+
}
113123
}

0 commit comments

Comments
 (0)