Skip to content

Commit

Permalink
Merge pull request #1 from codycraven/fix-outline-screenshots
Browse files Browse the repository at this point in the history
Scenario Outline screenshots overwrite previous loops
  • Loading branch information
ElkanRoelen authored Nov 14, 2016
2 parents 7a40baf + e4f6677 commit 10a8942
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/Context/BehatFormatterContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

/*
Expand Down Expand Up @@ -131,4 +131,4 @@ public static function transform($stepText){
}
return $stepText;
}
}
}
18 changes: 17 additions & 1 deletion src/Formatter/BehatFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,16 @@ class BehatFormatter implements Formatter {
*/
private $currentScenario;

/**
* @var int
*/
private $currentExampleCount;

/**
* @var Array|null
*/
private $currentExampleLines;

/**
* @var Scenario[]
*/
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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)){
Expand Down

0 comments on commit 10a8942

Please sign in to comment.