|
4 | 4 |
|
5 | 5 | use Behat\Gherkin\Node\StepNode; |
6 | 6 | use Behat\Behat\Hook\Scope\AfterStepScope; |
| 7 | +use Behat\Mink\Exception\UnsupportedDriverActionException; |
7 | 8 |
|
8 | 9 | class DebugContext extends BaseContext |
9 | 10 | { |
@@ -48,22 +49,22 @@ public function iSaveAScreenshotIn($filename) |
48 | 49 | */ |
49 | 50 | public function failScreenshots(AfterStepScope $scope) |
50 | 51 | { |
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())); |
66 | 64 | } |
| 65 | + |
| 66 | + $filename = sprintf('fail_%s_%s_%s_%s.png', time(), $suiteName, $featureName, $scenarioName); |
| 67 | + $this->saveScreenshot($filename, $this->screenshotDir); |
67 | 68 | } |
68 | 69 |
|
69 | 70 | /** |
@@ -110,4 +111,13 @@ function (StepNode $step) { |
110 | 111 |
|
111 | 112 | return false; |
112 | 113 | } |
| 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 | + } |
113 | 123 | } |
0 commit comments