From e4f6677154f029d32bdfdb284896832032b0af84 Mon Sep 17 00:00:00 2001 From: Cody Craven Date: Mon, 7 Nov 2016 15:55:00 -0800 Subject: [PATCH] Fixed screenshot paths to work with Outlines --- src/Context/BehatFormatterContext.php | 4 ++-- src/Formatter/BehatFormatter.php | 18 +++++++++++++++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/Context/BehatFormatterContext.php b/src/Context/BehatFormatterContext.php index ef23325..232dcc4 100644 --- a/src/Context/BehatFormatterContext.php +++ b/src/Context/BehatFormatterContext.php @@ -64,7 +64,7 @@ public function afterStepScreenShotOnFailure(AfterStepScope $scope) } //create filename string - $fileName = $currentSuite.".".basename($scope->getFeature()->getFile()).'.'.$scope->getStep()->getLine().'.png'; + $fileName = $currentSuite.".".basename($scope->getFeature()->getFile()).'.'.$this->currentScenario->getLine().'.'.$scope->getStep()->getLine().'.png'; $fileName = str_replace('.feature', '', $fileName); /* @@ -131,4 +131,4 @@ public static function transform($stepText){ } return $stepText; } -} \ No newline at end of file +} diff --git a/src/Formatter/BehatFormatter.php b/src/Formatter/BehatFormatter.php index 1aa75d1..c4eb7de 100644 --- a/src/Formatter/BehatFormatter.php +++ b/src/Formatter/BehatFormatter.php @@ -145,6 +145,16 @@ class BehatFormatter implements Formatter { */ private $currentScenario; + /** + * @var int + */ + private $currentExampleCount; + + /** + * @var Array|null + */ + private $currentExampleLines; + /** * @var Scenario[] */ @@ -650,6 +660,10 @@ public function onBeforeOutlineTested(BeforeOutlineTested $event) $scenario->setTags($event->getOutline()->getTags()); $scenario->setLine($event->getOutline()->getLine()); $this->currentScenario = $scenario; + $this->currentExampleCount = 0; + $this->currentExampleLines = array_map(function ($example) { + return $example->getLine(); + }, $event->getOutline()->getExamples()); $print = $this->renderer->renderBeforeOutline($this); $this->printer->writeln($print); @@ -673,6 +687,7 @@ public function onAfterOutlineTested(AfterOutlineTested $event) $this->currentScenario->setLoopCount(sizeof($event->getTestResult())); $this->currentScenario->setPassed($event->getTestResult()->isPassed()); $this->currentFeature->addScenario($this->currentScenario); + $this->currentExampleLines = null; $print = $this->renderer->renderAfterOutline($this); $this->printer->writeln($print); @@ -731,7 +746,8 @@ public function onAfterStepTested(AfterStepTested $event) } } if(($step->getResultCode() == "99") || ($step->getResult()->isPassed() && $step->getKeyword() === "Then")){ - $screenshot = $event->getSuite()->getName().".".basename($event->getFeature()->getFile()).".".$event->getStep()->getLine().".png"; + $scenarioLine = empty($this->currentExampleLines) ? $this->currentScenario->getLine() : $this->currentExampleLines[$this->currentExampleCount++]; + $screenshot = $event->getSuite()->getName().".".basename($event->getFeature()->getFile()).".$scenarioLine.".$event->getStep()->getLine().".png"; $screenshot = str_replace('.feature', '', $screenshot); if (file_exists(getcwd().DIRECTORY_SEPARATOR.".tmp_behatFormatter".DIRECTORY_SEPARATOR.$screenshot)){