From 923cffedaa8f4088119a21b40f31054387ba1bcc Mon Sep 17 00:00:00 2001 From: Dan Talash Date: Thu, 17 Aug 2017 11:36:07 -0700 Subject: [PATCH] * Using a path relative to the output path to hold screenshots, instead of a hardcoded /results/html folder. * This allows for the generation of independent report folders, each with their own screenshots. --- src/Classes/Scenario.php | 6 ++++-- src/Formatter/BehatHTMLFormatter.php | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Classes/Scenario.php b/src/Classes/Scenario.php index b05f212..b4fc5fe 100644 --- a/src/Classes/Scenario.php +++ b/src/Classes/Scenario.php @@ -198,8 +198,10 @@ public function setScreenshotPath($string) */ public function getScreenshotPath() { - if (file_exists('results/html/' . $this->screenshotPath)) { - return $this->screenshotPath; + if (file_exists($this->screenshotPath)) { + return "file://" . realpath($this->screenshotPath); } + + return false; } } diff --git a/src/Formatter/BehatHTMLFormatter.php b/src/Formatter/BehatHTMLFormatter.php index 8bb0a3c..3a22bd7 100644 --- a/src/Formatter/BehatHTMLFormatter.php +++ b/src/Formatter/BehatHTMLFormatter.php @@ -470,7 +470,8 @@ public function onBeforeScenarioTested(BeforeScenarioTested $event) $scenario->setLine($event->getScenario()->getLine()); $scenario->setScreenshotName($event->getScenario()->getTitle()); $scenario->setScreenshotPath( - 'assets/screenshots/' . + $this->printer->getOutputPath() . + '/assets/screenshots/' . preg_replace('/\W/', '', $event->getFeature()->getTitle()) . '/'. preg_replace('/\W/', '', $event->getScenario()->getTitle()) . '.png' );