From 92e6b01e8aa2759f3120cfae52f7cfb8405b3181 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20Petry?= Date: Thu, 27 May 2021 16:20:25 +0200 Subject: [PATCH 01/25] php 8 support --- src/Printer/FileOutputPrinter.php | 34 ++++++++++++++++++------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/src/Printer/FileOutputPrinter.php b/src/Printer/FileOutputPrinter.php index 1289a3a..bd0a0cb 100644 --- a/src/Printer/FileOutputPrinter.php +++ b/src/Printer/FileOutputPrinter.php @@ -60,22 +60,22 @@ public function setOutputPath($path) if (!file_exists($outpath)) { if (!mkdir($outpath, 0755, true)) { throw new BadOutputPathException( - sprintf( - 'Output path %s does not exist and could not be created!', - $outpath - ), - $outpath - ); + sprintf( + 'Output path %s does not exist and could not be created!', + $outpath + ), + $outpath + ); } } else { if (!is_dir(realpath($outpath))) { throw new BadOutputPathException( - sprintf( - 'The argument to `output` is expected to the a directory, but got %s!', - $outpath - ), - $outpath - ); + sprintf( + 'The argument to `output` is expected to the a directory, but got %s!', + $outpath + ), + $outpath + ); } } $this->outputPath = $outpath; @@ -207,7 +207,10 @@ public function copyAssets($renderer) //first create the assets dir $destination = $this->outputPath.DIRECTORY_SEPARATOR.'assets'; - @mkdir($destination); + + if (!file_exists($destination)) { + mkdir($destination); + } $this->recurse_copy($assets_source, $destination.DIRECTORY_SEPARATOR.$renderer); } @@ -221,7 +224,10 @@ public function copyAssets($renderer) private function recurse_copy($src, $dst) { $dir = opendir($src); - @mkdir($dst); + if (!file_exists($dst)) { + mkdir($dst); + } + while (false !== ($file = readdir($dir))) { if (('.' != $file) && ('..' != $file)) { if (is_dir($src.'/'.$file)) { From 494aa0770ec6d196f061f205dd87129cacb61d54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20Petry?= Date: Fri, 28 May 2021 12:24:49 +0200 Subject: [PATCH 02/25] php 8 support --- src/Renderer/TwigRenderer.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Renderer/TwigRenderer.php b/src/Renderer/TwigRenderer.php index c86659d..c025949 100644 --- a/src/Renderer/TwigRenderer.php +++ b/src/Renderer/TwigRenderer.php @@ -3,8 +3,8 @@ namespace emuse\BehatHTMLFormatter\Renderer; use emuse\BehatHTMLFormatter\Formatter\BehatHTMLFormatter; -use Twig_Environment; -use Twig_Loader_Filesystem; +use \Twig\Environment as Twig_Environment; +use \Twig\Loader\FilesystemLoader as Twig_Loader_Filesystem; /** * Twig renderer for Behat report. From 507616dc74fe79092ecfcc090ecddc458a68cf8f Mon Sep 17 00:00:00 2001 From: "rafal.miedziocha" Date: Thu, 25 Nov 2021 20:31:23 +0100 Subject: [PATCH 03/25] V10AGILE-6561: Fix dependency for onAfterSuiteTested hook [run ci] --- src/Formatter/BehatHTMLFormatter.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Formatter/BehatHTMLFormatter.php b/src/Formatter/BehatHTMLFormatter.php index 5514455..15dddfa 100644 --- a/src/Formatter/BehatHTMLFormatter.php +++ b/src/Formatter/BehatHTMLFormatter.php @@ -15,9 +15,9 @@ use Behat\Testwork\Counter\Memory; use Behat\Testwork\Counter\Timer; use Behat\Testwork\EventDispatcher\Event\AfterExerciseCompleted; -use Behat\Testwork\EventDispatcher\Event\AfterSuiteTested; use Behat\Testwork\EventDispatcher\Event\BeforeExerciseCompleted; use Behat\Testwork\EventDispatcher\Event\BeforeSuiteTested; +use Behat\Testwork\EventDispatcher\Event\SuiteTested; use Behat\Testwork\Output\Formatter; use Behat\Testwork\Output\Printer\OutputPrinter; use emuse\BehatHTMLFormatter\Classes\Feature; @@ -431,9 +431,9 @@ public function onBeforeSuiteTested(BeforeSuiteTested $event) } /** - * @param AfterSuiteTested $event + * @param SuiteTested $event */ - public function onAfterSuiteTested(AfterSuiteTested $event) + public function onAfterSuiteTested(SuiteTested $event) { $this->suites[] = $this->currentSuite; From 8f35802a24d2f95d290e090d721fae85ccbf55dc Mon Sep 17 00:00:00 2001 From: "rafal.miedziocha" Date: Thu, 25 Nov 2021 20:51:52 +0100 Subject: [PATCH 04/25] V10AGILE-6561: Reformat code [run ci] --- README.md | 5 ----- src/Printer/FileOutputPrinter.php | 22 +++++++++++----------- src/Renderer/TwigRenderer.php | 8 ++++---- 3 files changed, 15 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 75aae84..11b43bf 100644 --- a/README.md +++ b/README.md @@ -8,11 +8,6 @@ Behat 3 extension for generating HTML reports from your test results. ![Twig Screenshot](http://i.imgur.com/o0zCqiB.png) -### Behat 2 report - -![Behat2 Screenshot](http://i57.tinypic.com/287g942.jpg) - - ## How? * The tool can be installed easily with composer. diff --git a/src/Printer/FileOutputPrinter.php b/src/Printer/FileOutputPrinter.php index bd0a0cb..9cd88ee 100644 --- a/src/Printer/FileOutputPrinter.php +++ b/src/Printer/FileOutputPrinter.php @@ -39,7 +39,7 @@ public function __construct($rendererList, $filename, $base_path) foreach ($rendererList as $renderer) { if ('generated' == $filename) { $date = date('YmdHis'); - $this->rendererFiles[$renderer] = $renderer.'_'.$date; + $this->rendererFiles[$renderer] = $renderer . '_' . $date; } else { $this->rendererFiles[$renderer] = $filename; } @@ -155,7 +155,7 @@ public function write($messages = array()) { //Write it for each message = each renderer foreach ($messages as $key => $message) { - $file = $this->outputPath.DIRECTORY_SEPARATOR.$this->rendererFiles[$key].'.html'; + $file = $this->outputPath . DIRECTORY_SEPARATOR . $this->rendererFiles[$key] . '.html'; file_put_contents($file, $message); $this->copyAssets($key); } @@ -170,7 +170,7 @@ public function writeln($messages = array()) { //Write it for each message = each renderer foreach ($messages as $key => $message) { - $file = $this->outputPath.DIRECTORY_SEPARATOR.$this->rendererFiles[$key].'.html'; + $file = $this->outputPath . DIRECTORY_SEPARATOR . $this->rendererFiles[$key] . '.html'; file_put_contents($file, $message, FILE_APPEND); } } @@ -184,9 +184,9 @@ public function writeBeginning($messages = array()) { //Write it for each message = each renderer foreach ($messages as $key => $message) { - $file = $this->outputPath.DIRECTORY_SEPARATOR.$this->rendererFiles[$key].'.html'; + $file = $this->outputPath . DIRECTORY_SEPARATOR . $this->rendererFiles[$key] . '.html'; $fileContents = file_get_contents($file); - file_put_contents($file, $message.$fileContents); + file_put_contents($file, $message . $fileContents); } } @@ -199,20 +199,20 @@ public function copyAssets($renderer) { // If the assets folder doesn' exist in the output path for this renderer, copy it $source = realpath(dirname(__FILE__)); - $assets_source = realpath($source.'/../../assets/'.$renderer); + $assets_source = realpath($source . '/../../assets/' . $renderer); if (false === $assets_source) { //There is no assets to copy for this renderer return; } //first create the assets dir - $destination = $this->outputPath.DIRECTORY_SEPARATOR.'assets'; + $destination = $this->outputPath . DIRECTORY_SEPARATOR . 'assets'; if (!file_exists($destination)) { mkdir($destination); } - $this->recurse_copy($assets_source, $destination.DIRECTORY_SEPARATOR.$renderer); + $this->recurse_copy($assets_source, $destination . DIRECTORY_SEPARATOR . $renderer); } /** @@ -230,10 +230,10 @@ private function recurse_copy($src, $dst) while (false !== ($file = readdir($dir))) { if (('.' != $file) && ('..' != $file)) { - if (is_dir($src.'/'.$file)) { - $this->recurse_copy($src.'/'.$file, $dst.'/'.$file); + if (is_dir($src . '/' . $file)) { + $this->recurse_copy($src . '/' . $file, $dst . '/' . $file); } else { - copy($src.'/'.$file, $dst.'/'.$file); + copy($src . '/' . $file, $dst . '/' . $file); } } } diff --git a/src/Renderer/TwigRenderer.php b/src/Renderer/TwigRenderer.php index c025949..baf2436 100644 --- a/src/Renderer/TwigRenderer.php +++ b/src/Renderer/TwigRenderer.php @@ -3,8 +3,8 @@ namespace emuse\BehatHTMLFormatter\Renderer; use emuse\BehatHTMLFormatter\Formatter\BehatHTMLFormatter; -use \Twig\Environment as Twig_Environment; -use \Twig\Loader\FilesystemLoader as Twig_Loader_Filesystem; +use Twig\Environment; +use Twig\Loader\FilesystemLoader; /** * Twig renderer for Behat report. @@ -35,8 +35,8 @@ public function renderBeforeExercise(BehatHTMLFormatter $obj) public function renderAfterExercise(BehatHTMLFormatter $obj) { $templatePath = dirname(__FILE__).'/../../templates'; - $loader = new Twig_Loader_Filesystem($templatePath); - $twig = new Twig_Environment($loader, array()); + $loader = new FilesystemLoader($templatePath); + $twig = new Environment($loader, array()); $print = $twig->render('index.html.twig', array( 'suites' => $obj->getSuites(), From 2d7839dd224ee317499ece5784a9f5c83bb0473e Mon Sep 17 00:00:00 2001 From: Daniel Meyer Date: Mon, 5 Dec 2022 13:32:36 +0100 Subject: [PATCH 05/25] Put screenshot into raport as base64 --- src/Context/ScreenshotContext.php | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/src/Context/ScreenshotContext.php b/src/Context/ScreenshotContext.php index 66546bc..6ffdd37 100644 --- a/src/Context/ScreenshotContext.php +++ b/src/Context/ScreenshotContext.php @@ -36,17 +36,6 @@ public function afterStep($scope) return; } - // create filename string - $featureFolder = preg_replace('/\W/', '', $scope->getFeature()->getTitle()); - - $scenarioName = $this->currentScenario->getTitle(); - $fileName = preg_replace('/\W/', '', $scenarioName).'.png'; - - // create screenshots directory if it doesn't exist - if (!file_exists($this->screenshotDir.'/'.$featureFolder)) { - mkdir($this->screenshotDir.'/'.$featureFolder); - } - - $this->saveScreenshot($fileName, $this->screenshotDir.'/'.$featureFolder.'/'); + $this->currentScenario->setScreenshotPath( 'data:image/jpeg;base64,' . base64_encode($this->getSession()->getScreenshot())); } } From de8436c187fdb9e3dfbbca3166a5a82d0bfdfab4 Mon Sep 17 00:00:00 2001 From: Daniel Meyer Date: Mon, 5 Dec 2022 13:39:07 +0100 Subject: [PATCH 06/25] Put screenshot into raport as base64 --- src/Classes/Scenario.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/Classes/Scenario.php b/src/Classes/Scenario.php index 7d422a7..1fc2369 100644 --- a/src/Classes/Scenario.php +++ b/src/Classes/Scenario.php @@ -202,10 +202,6 @@ public function getScreenshotPath() */ public function getRelativeScreenshotPath() { - if (!file_exists($this->screenshotPath)) { - return false; - } - - return '.'.substr($this->screenshotPath, strpos($this->screenshotPath, '/assets/screenshots')); + return $this->screenshotPath ?: false; } } From 489f3c3db0832a6806b86853783d9df33790fdaf Mon Sep 17 00:00:00 2001 From: Daniel Meyer Date: Mon, 5 Dec 2022 13:42:46 +0100 Subject: [PATCH 07/25] Put screenshot into raport as base64 --- src/Classes/Scenario.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Classes/Scenario.php b/src/Classes/Scenario.php index 1fc2369..2baf266 100644 --- a/src/Classes/Scenario.php +++ b/src/Classes/Scenario.php @@ -202,6 +202,6 @@ public function getScreenshotPath() */ public function getRelativeScreenshotPath() { - return $this->screenshotPath ?: false; + return substr($this->screenshotPath, 0, 10) === 'data:image' ? $this->screenshotPath : false; } } From daa34f2743fafe97f5d2c7868d9c57177fa817fc Mon Sep 17 00:00:00 2001 From: Daniel Meyer Date: Wed, 7 Dec 2022 12:00:59 +0100 Subject: [PATCH 08/25] Update index.html.twig --- templates/index.html.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/index.html.twig b/templates/index.html.twig index 57e2505..1926a8a 100644 --- a/templates/index.html.twig +++ b/templates/index.html.twig @@ -193,7 +193,7 @@ {% for tag in scenario.tags %} {{ tag }} {% endfor %} - {% if scenario.getRelativeScreenshotPath() %} + {% if scenario.hasScreenshot() %} Screenshot {% endif %} From 990b0dcbee2a5a88b3a10fdb84c437d99d9ec69b Mon Sep 17 00:00:00 2001 From: Daniel Meyer Date: Wed, 7 Dec 2022 12:01:38 +0100 Subject: [PATCH 09/25] Update ScreenshotContext.php --- src/Context/ScreenshotContext.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Context/ScreenshotContext.php b/src/Context/ScreenshotContext.php index 6ffdd37..66546bc 100644 --- a/src/Context/ScreenshotContext.php +++ b/src/Context/ScreenshotContext.php @@ -36,6 +36,17 @@ public function afterStep($scope) return; } - $this->currentScenario->setScreenshotPath( 'data:image/jpeg;base64,' . base64_encode($this->getSession()->getScreenshot())); + // create filename string + $featureFolder = preg_replace('/\W/', '', $scope->getFeature()->getTitle()); + + $scenarioName = $this->currentScenario->getTitle(); + $fileName = preg_replace('/\W/', '', $scenarioName).'.png'; + + // create screenshots directory if it doesn't exist + if (!file_exists($this->screenshotDir.'/'.$featureFolder)) { + mkdir($this->screenshotDir.'/'.$featureFolder); + } + + $this->saveScreenshot($fileName, $this->screenshotDir.'/'.$featureFolder.'/'); } } From 92c0b38642bf9dcdb90d30a6535f8916f4e07baf Mon Sep 17 00:00:00 2001 From: Daniel Meyer Date: Wed, 7 Dec 2022 12:02:38 +0100 Subject: [PATCH 10/25] Update Scenario.php --- src/Classes/Scenario.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Classes/Scenario.php b/src/Classes/Scenario.php index 2baf266..3faaa99 100644 --- a/src/Classes/Scenario.php +++ b/src/Classes/Scenario.php @@ -198,10 +198,19 @@ public function getScreenshotPath() /** * Gets relative path for screenshot. * - * @return bool|string + * @return string */ public function getRelativeScreenshotPath() { - return substr($this->screenshotPath, 0, 10) === 'data:image' ? $this->screenshotPath : false; + if (!$this->hasScreenshot()) { + return ''; + } + + return 'data:image/jpeg;base64,' . base64_encode(file_get_contents($this->screenshotPath)); + } + + public function hasScreenshot() + { + return file_exists($this->screenshotPath); } } From 67a938e68ab808dbe5220f776837335e373b2d54 Mon Sep 17 00:00:00 2001 From: Daniel Meyer Date: Wed, 7 Dec 2022 12:31:26 +0100 Subject: [PATCH 11/25] Update Scenario.php --- src/Classes/Scenario.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Classes/Scenario.php b/src/Classes/Scenario.php index 3faaa99..e92c755 100644 --- a/src/Classes/Scenario.php +++ b/src/Classes/Scenario.php @@ -206,11 +206,16 @@ public function getRelativeScreenshotPath() return ''; } - return 'data:image/jpeg;base64,' . base64_encode(file_get_contents($this->screenshotPath)); + return $this->hasScreenshotData() ? $this->screenshotPath : 'data:image/jpeg;base64,' . base64_encode(file_get_contents($this->screenshotPath)); } public function hasScreenshot() { - return file_exists($this->screenshotPath); + return $this->hasScreenshotData() || file_exists($this->screenshotPath); + } + + public function hasScreenshotData() + { + return substr($this->screenshotPath, 0, 10) === 'data:image'; } } From 42eb900b3c5fec6f0e20e01992b317d798897a48 Mon Sep 17 00:00:00 2001 From: Daniel Meyer Date: Wed, 7 Dec 2022 19:51:56 +0100 Subject: [PATCH 12/25] Update ScreenshotContext.php --- src/Context/ScreenshotContext.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Context/ScreenshotContext.php b/src/Context/ScreenshotContext.php index 66546bc..88f4abc 100644 --- a/src/Context/ScreenshotContext.php +++ b/src/Context/ScreenshotContext.php @@ -47,6 +47,8 @@ public function afterStep($scope) mkdir($this->screenshotDir.'/'.$featureFolder); } - $this->saveScreenshot($fileName, $this->screenshotDir.'/'.$featureFolder.'/'); + $this->saveScreenshot($fileName, $this->screenshotDir.'/'.$featureFolder); + $file = $this->screenshotDir.'/'.$featureFolder.'/'.$fileName; + echo file_exists($file) ? "Saved screen: $file" : "Cannot save screen: $file"; } } From 41a8262292d41db8efb872c6e02d59c2e54502bf Mon Sep 17 00:00:00 2001 From: Daniel Meyer Date: Wed, 7 Dec 2022 19:52:44 +0100 Subject: [PATCH 13/25] Update BehatHTMLFormatter.php --- src/Formatter/BehatHTMLFormatter.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Formatter/BehatHTMLFormatter.php b/src/Formatter/BehatHTMLFormatter.php index 15dddfa..101daeb 100644 --- a/src/Formatter/BehatHTMLFormatter.php +++ b/src/Formatter/BehatHTMLFormatter.php @@ -487,8 +487,7 @@ public function onBeforeScenarioTested(BeforeScenarioTested $event) $scenario->setLine($event->getScenario()->getLine()); $scenario->setScreenshotName($event->getScenario()->getTitle()); $scenario->setScreenshotPath( - $this->printer->getOutputPath(). - '/assets/screenshots/'. + '/tmp/'. preg_replace('/\W/', '', $event->getFeature()->getTitle()).'/'. preg_replace('/\W/', '', $event->getScenario()->getTitle()).'.png' ); From 764b36dcfc635e7b0f0a57d176cb9beb95ee6dde Mon Sep 17 00:00:00 2001 From: Daniel Meyer Date: Thu, 8 Dec 2022 07:34:00 +0100 Subject: [PATCH 14/25] Update BehatHTMLFormatter.php --- src/Formatter/BehatHTMLFormatter.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Formatter/BehatHTMLFormatter.php b/src/Formatter/BehatHTMLFormatter.php index 101daeb..2f72bda 100644 --- a/src/Formatter/BehatHTMLFormatter.php +++ b/src/Formatter/BehatHTMLFormatter.php @@ -535,6 +535,12 @@ public function onBeforeOutlineTested(BeforeOutlineTested $event) $scenario->setName($event->getOutline()->getTitle()); $scenario->setTags($event->getOutline()->getTags()); $scenario->setLine($event->getOutline()->getLine()); + $scenario->setScreenshotName($event->getScenario()->getTitle()); + $scenario->setScreenshotPath( + '/tmp/'. + preg_replace('/\W/', '', $event->getFeature()->getTitle()).'/'. + preg_replace('/\W/', '', $event->getScenario()->getTitle()).'.png' + ); $this->currentScenario = $scenario; $print = $this->renderer->renderBeforeOutline($this); From 1efe7f4c418fa7b40007534967857d8bcdd255f9 Mon Sep 17 00:00:00 2001 From: Daniel Meyer Date: Thu, 8 Dec 2022 07:34:45 +0100 Subject: [PATCH 15/25] Update ScreenshotContext.php --- src/Context/ScreenshotContext.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Context/ScreenshotContext.php b/src/Context/ScreenshotContext.php index 88f4abc..691a258 100644 --- a/src/Context/ScreenshotContext.php +++ b/src/Context/ScreenshotContext.php @@ -49,6 +49,6 @@ public function afterStep($scope) $this->saveScreenshot($fileName, $this->screenshotDir.'/'.$featureFolder); $file = $this->screenshotDir.'/'.$featureFolder.'/'.$fileName; - echo file_exists($file) ? "Saved screen: $file" : "Cannot save screen: $file"; + echo file_exists($file) ? "Saved screenshot: $file" : "Cannot save screenshot: $file"; } } From 52acb03cd110e952016daac610b7c27fa3855a17 Mon Sep 17 00:00:00 2001 From: Daniel Meyer Date: Thu, 8 Dec 2022 08:34:54 +0100 Subject: [PATCH 16/25] Update BehatHTMLFormatter.php --- src/Formatter/BehatHTMLFormatter.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Formatter/BehatHTMLFormatter.php b/src/Formatter/BehatHTMLFormatter.php index 2f72bda..3312417 100644 --- a/src/Formatter/BehatHTMLFormatter.php +++ b/src/Formatter/BehatHTMLFormatter.php @@ -535,11 +535,11 @@ public function onBeforeOutlineTested(BeforeOutlineTested $event) $scenario->setName($event->getOutline()->getTitle()); $scenario->setTags($event->getOutline()->getTags()); $scenario->setLine($event->getOutline()->getLine()); - $scenario->setScreenshotName($event->getScenario()->getTitle()); + $scenario->setScreenshotName($event->getOutline()->getTitle()); $scenario->setScreenshotPath( '/tmp/'. preg_replace('/\W/', '', $event->getFeature()->getTitle()).'/'. - preg_replace('/\W/', '', $event->getScenario()->getTitle()).'.png' + preg_replace('/\W/', '', $event->getOutline()->getTitle()).'.png' ); $this->currentScenario = $scenario; From c4187c84f1cd98906fbdf8bcb7148701c5b840a1 Mon Sep 17 00:00:00 2001 From: Daniel Meyer Date: Thu, 8 Dec 2022 12:09:36 +0100 Subject: [PATCH 17/25] Update ScreenshotContext.php --- src/Context/ScreenshotContext.php | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/Context/ScreenshotContext.php b/src/Context/ScreenshotContext.php index 691a258..b324bcd 100644 --- a/src/Context/ScreenshotContext.php +++ b/src/Context/ScreenshotContext.php @@ -7,6 +7,7 @@ class ScreenshotContext extends RawMinkContext { private $currentScenario; + private $currentFeature; private $screenshotDir; public function __construct($screenshotDir) @@ -22,6 +23,7 @@ public function __construct($screenshotDir) public function setUpTestEnvironment($scope) { $this->currentScenario = $scope->getScenario(); + $this->currentFeature = $scope->getFeature(); } /** @@ -37,18 +39,17 @@ public function afterStep($scope) } // create filename string - $featureFolder = preg_replace('/\W/', '', $scope->getFeature()->getTitle()); - - $scenarioName = $this->currentScenario->getTitle(); - $fileName = preg_replace('/\W/', '', $scenarioName).'.png'; + $featureFolder = preg_replace('/\W/', '', $this->currentFeature->getTitle()); + $fileName = preg_replace('/\W/', '', $this->currentScenario->getTitle()).'.png'; + $screenshotDir = $this->screenshotDir.'/'.$featureFolder; // create screenshots directory if it doesn't exist - if (!file_exists($this->screenshotDir.'/'.$featureFolder)) { - mkdir($this->screenshotDir.'/'.$featureFolder); + if (!file_exists($screenshotDir)) { + mkdir($screenshotDir); } - $this->saveScreenshot($fileName, $this->screenshotDir.'/'.$featureFolder); - $file = $this->screenshotDir.'/'.$featureFolder.'/'.$fileName; + $this->saveScreenshot($fileName, $screenshotDir); + $file = $screenshotDir . '/' . $fileName; echo file_exists($file) ? "Saved screenshot: $file" : "Cannot save screenshot: $file"; } } From 283707a8757d4bc2a7c84e6c1b9671f152c388f3 Mon Sep 17 00:00:00 2001 From: Daniel Meyer Date: Fri, 9 Dec 2022 15:26:44 +0100 Subject: [PATCH 18/25] Update BehatHTMLFormatter.php --- src/Formatter/BehatHTMLFormatter.php | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/Formatter/BehatHTMLFormatter.php b/src/Formatter/BehatHTMLFormatter.php index 3312417..d1e8814 100644 --- a/src/Formatter/BehatHTMLFormatter.php +++ b/src/Formatter/BehatHTMLFormatter.php @@ -24,6 +24,7 @@ use emuse\BehatHTMLFormatter\Classes\Scenario; use emuse\BehatHTMLFormatter\Classes\Step; use emuse\BehatHTMLFormatter\Classes\Suite; +use emuse\BehatHTMLFormatter\Context\ScreenshotContext; use emuse\BehatHTMLFormatter\Printer\FileOutputPrinter; use emuse\BehatHTMLFormatter\Renderer\BaseRenderer; @@ -491,6 +492,7 @@ public function onBeforeScenarioTested(BeforeScenarioTested $event) preg_replace('/\W/', '', $event->getFeature()->getTitle()).'/'. preg_replace('/\W/', '', $event->getScenario()->getTitle()).'.png' ); + ScreenshotContext::setScreenshotPath($event->getScreenshotPath()); $this->currentScenario = $scenario; $print = $this->renderer->renderBeforeScenario($this); @@ -535,12 +537,6 @@ public function onBeforeOutlineTested(BeforeOutlineTested $event) $scenario->setName($event->getOutline()->getTitle()); $scenario->setTags($event->getOutline()->getTags()); $scenario->setLine($event->getOutline()->getLine()); - $scenario->setScreenshotName($event->getOutline()->getTitle()); - $scenario->setScreenshotPath( - '/tmp/'. - preg_replace('/\W/', '', $event->getFeature()->getTitle()).'/'. - preg_replace('/\W/', '', $event->getOutline()->getTitle()).'.png' - ); $this->currentScenario = $scenario; $print = $this->renderer->renderBeforeOutline($this); From bf96345b6da5ecf325d549be9a25929d8e93448b Mon Sep 17 00:00:00 2001 From: Daniel Meyer Date: Fri, 9 Dec 2022 15:28:24 +0100 Subject: [PATCH 19/25] Update ScreenshotContext.php --- src/Context/ScreenshotContext.php | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/src/Context/ScreenshotContext.php b/src/Context/ScreenshotContext.php index b324bcd..09201da 100644 --- a/src/Context/ScreenshotContext.php +++ b/src/Context/ScreenshotContext.php @@ -6,24 +6,11 @@ class ScreenshotContext extends RawMinkContext { - private $currentScenario; - private $currentFeature; - private $screenshotDir; + private static $screenshotPath; - public function __construct($screenshotDir) + public static function setScreenshotPath($screenshotPath) { - $this->screenshotDir = $screenshotDir; - } - - /** - * @BeforeScenario - * - * @param BeforeScenarioScope $scope - */ - public function setUpTestEnvironment($scope) - { - $this->currentScenario = $scope->getScenario(); - $this->currentFeature = $scope->getFeature(); + self::$screenshotPath = $screenshotPath; } /** @@ -39,9 +26,8 @@ public function afterStep($scope) } // create filename string - $featureFolder = preg_replace('/\W/', '', $this->currentFeature->getTitle()); - $fileName = preg_replace('/\W/', '', $this->currentScenario->getTitle()).'.png'; - $screenshotDir = $this->screenshotDir.'/'.$featureFolder; + $fileName = basename(self::$screenshotPath); + $screenshotDir = str_replace('/' . $fileName, '', self::$screenshotPath); // create screenshots directory if it doesn't exist if (!file_exists($screenshotDir)) { @@ -49,7 +35,7 @@ public function afterStep($scope) } $this->saveScreenshot($fileName, $screenshotDir); - $file = $screenshotDir . '/' . $fileName; + $file = $screenshotDir . '/' . $fileName; echo file_exists($file) ? "Saved screenshot: $file" : "Cannot save screenshot: $file"; } } From cb17b8922c56210aed1d66b7e08b7c95c0f6b0b3 Mon Sep 17 00:00:00 2001 From: Daniel Meyer Date: Fri, 9 Dec 2022 15:30:10 +0100 Subject: [PATCH 20/25] Update ScreenshotContext.php --- src/Context/ScreenshotContext.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Context/ScreenshotContext.php b/src/Context/ScreenshotContext.php index 09201da..a564400 100644 --- a/src/Context/ScreenshotContext.php +++ b/src/Context/ScreenshotContext.php @@ -24,6 +24,9 @@ public function afterStep($scope) if ($scope->getTestResult()->isPassed()) { return; } + if (!self::$screenshotPath) { + echo 'Screenshot path is empty!'; + } // create filename string $fileName = basename(self::$screenshotPath); From 32a0af8e92d800b83bb5dbccf0000e9efe1989ce Mon Sep 17 00:00:00 2001 From: Daniel Meyer Date: Fri, 9 Dec 2022 17:03:09 +0100 Subject: [PATCH 21/25] Update BehatHTMLFormatter.php --- src/Formatter/BehatHTMLFormatter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Formatter/BehatHTMLFormatter.php b/src/Formatter/BehatHTMLFormatter.php index d1e8814..319e583 100644 --- a/src/Formatter/BehatHTMLFormatter.php +++ b/src/Formatter/BehatHTMLFormatter.php @@ -492,7 +492,7 @@ public function onBeforeScenarioTested(BeforeScenarioTested $event) preg_replace('/\W/', '', $event->getFeature()->getTitle()).'/'. preg_replace('/\W/', '', $event->getScenario()->getTitle()).'.png' ); - ScreenshotContext::setScreenshotPath($event->getScreenshotPath()); + ScreenshotContext::setScreenshotPath($scenario->getScreenshotPath()); $this->currentScenario = $scenario; $print = $this->renderer->renderBeforeScenario($this); From da230f66a535899ec0fd31d3a4a7b54347409db8 Mon Sep 17 00:00:00 2001 From: Daniel Meyer Date: Fri, 9 Dec 2022 20:10:05 +0100 Subject: [PATCH 22/25] Update ScreenshotContext.php --- src/Context/ScreenshotContext.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Context/ScreenshotContext.php b/src/Context/ScreenshotContext.php index a564400..bd68326 100644 --- a/src/Context/ScreenshotContext.php +++ b/src/Context/ScreenshotContext.php @@ -7,6 +7,11 @@ class ScreenshotContext extends RawMinkContext { private static $screenshotPath; + + public function __construct($screenshotDir) + { + // $this->screenshotDir = $screenshotDir; + } public static function setScreenshotPath($screenshotPath) { From 10583221d98bc236dde0518263e0513051116694 Mon Sep 17 00:00:00 2001 From: Daniel Meyer Date: Sat, 10 Dec 2022 10:54:41 +0100 Subject: [PATCH 23/25] Update ScreenshotContext.php --- src/Context/ScreenshotContext.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Context/ScreenshotContext.php b/src/Context/ScreenshotContext.php index bd68326..4de41b2 100644 --- a/src/Context/ScreenshotContext.php +++ b/src/Context/ScreenshotContext.php @@ -31,6 +31,7 @@ public function afterStep($scope) } if (!self::$screenshotPath) { echo 'Screenshot path is empty!'; + return; } // create filename string From c938c1835cc8ea0de66004fda02fb6f13f8b617f Mon Sep 17 00:00:00 2001 From: Daniel Meyer Date: Sat, 10 Dec 2022 10:55:12 +0100 Subject: [PATCH 24/25] Update Scenario.php --- src/Classes/Scenario.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Classes/Scenario.php b/src/Classes/Scenario.php index e92c755..869e326 100644 --- a/src/Classes/Scenario.php +++ b/src/Classes/Scenario.php @@ -206,7 +206,7 @@ public function getRelativeScreenshotPath() return ''; } - return $this->hasScreenshotData() ? $this->screenshotPath : 'data:image/jpeg;base64,' . base64_encode(file_get_contents($this->screenshotPath)); + return $this->hasScreenshotData() ? $this->screenshotPath : 'data:image/png;base64,' . base64_encode(file_get_contents($this->screenshotPath)); } public function hasScreenshot() From 0351e9d9277ffd8079cc17b5bf19d519fd859728 Mon Sep 17 00:00:00 2001 From: Daniel Meyer Date: Sat, 10 Dec 2022 10:57:02 +0100 Subject: [PATCH 25/25] Update BehatHTMLFormatter.php --- src/Formatter/BehatHTMLFormatter.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Formatter/BehatHTMLFormatter.php b/src/Formatter/BehatHTMLFormatter.php index 319e583..678d1c5 100644 --- a/src/Formatter/BehatHTMLFormatter.php +++ b/src/Formatter/BehatHTMLFormatter.php @@ -537,6 +537,12 @@ public function onBeforeOutlineTested(BeforeOutlineTested $event) $scenario->setName($event->getOutline()->getTitle()); $scenario->setTags($event->getOutline()->getTags()); $scenario->setLine($event->getOutline()->getLine()); + $scenario->setScreenshotName($event->getOutline()->getTitle()); + $scenario->setScreenshotPath( + '/tmp/'. + preg_replace('/\W/', '', $event->getFeature()->getTitle()).'/'. + preg_replace('/\W/', '', $event->getOutline()->getTitle()).'.png' + ); $this->currentScenario = $scenario; $print = $this->renderer->renderBeforeOutline($this);