From b22be920abaa7e87fc4d4f6317676b69fbdadf27 Mon Sep 17 00:00:00 2001 From: Martin Jainta Date: Thu, 21 Nov 2024 14:34:57 +0100 Subject: [PATCH 1/2] Support the step output with the Behat2 renderer --- features/behat2_renderer.feature | 115 ++++++++++++++++++++++++++ features/bootstrap/FeatureContext.php | 17 ++-- features/twig_renderer.feature | 2 +- src/Renderer/Behat2Renderer.php | 7 ++ 4 files changed, 133 insertions(+), 8 deletions(-) create mode 100644 features/behat2_renderer.feature diff --git a/features/behat2_renderer.feature b/features/behat2_renderer.feature new file mode 100644 index 0000000..7d1966c --- /dev/null +++ b/features/behat2_renderer.feature @@ -0,0 +1,115 @@ + Feature: Behat2 Renderer + + Background: + Given a file named "behat.yml" with: + """ + default: + formatters: + html: + output_path: %paths.base%/build + extensions: + emuse\BehatHTMLFormatter\BehatHTMLFormatterExtension: + name: html + renderer: Behat2 + file_name: Index + print_args: true + print_outp: true + loop_break: true + suites: + suite1: + paths: [ "%paths.base%/features/suite1" ] + suite2: + paths: [ "%paths.base%/features/suite2" ] + suite3: + paths: [ "%paths.base%/features/suite3" ] + """ + Given a file named "features/bootstrap/FeatureContext.php" with: + """ + + 3 features ( 1 success 2 fail ) +

+

+ 7 scenarios ( 2 success 5 fail ) +

+

+ 9 steps ( 4 success 3 pending 2 fail ) +

+ """ + And report file should contain: + """ + I am a passing step + """ + And report file should contain: + """ + I am a failing step + """ diff --git a/features/bootstrap/FeatureContext.php b/features/bootstrap/FeatureContext.php index 4d137ea..568c78b 100644 --- a/features/bootstrap/FeatureContext.php +++ b/features/bootstrap/FeatureContext.php @@ -335,15 +335,18 @@ public function processOutputShouldBe(PyStringNode $expected) /** - * @Given report file should exists + * @Given /report file for (Twig|Behat2) should exists/ */ - public function reportFileShouldExists() + public function reportFileShouldExists(string $reportType) { - $files = array( - $this->reportDir . 'Index.html', - $this->reportDir . 'assets/Twig/css/style.css', - $this->reportDir . 'assets/Twig/css/style.less', - ); + $files = []; + if ($reportType === 'Behat2') { + $files[] = $this->reportDir . 'Index.html'; + } elseif ($reportType === 'Twig') { + $files[] = $this->reportDir . 'Index.html'; + $files[] = $this->reportDir . 'assets/Twig/css/style.css'; + $files[] = $this->reportDir . 'assets/Twig/css/style.less'; + } foreach ($files as $file) { PHPUnit_Framework_Assert::assertFileExists($file); diff --git a/features/twig_renderer.feature b/features/twig_renderer.feature index 897f7ff..e874dad 100644 --- a/features/twig_renderer.feature +++ b/features/twig_renderer.feature @@ -91,7 +91,7 @@ """ - And report file should exists + And report file for Twig should exists And report file should contain: """ 2 features failed of 3 diff --git a/src/Renderer/Behat2Renderer.php b/src/Renderer/Behat2Renderer.php index f4aeb6f..9de4e8f 100644 --- a/src/Renderer/Behat2Renderer.php +++ b/src/Renderer/Behat2Renderer.php @@ -438,6 +438,13 @@ public function renderAfterStep($obj) $print .= 'Screenshot'; } } + + $output = $step->getOutput(); + if (!empty($output)) { + $print .= ' +
'.$output.'
'; + } + $print .= ' '; From e065e3f0c10a3491e854451f8b266933c4b9e9ef Mon Sep 17 00:00:00 2001 From: Martin Jainta Date: Thu, 21 Nov 2024 15:28:54 +0100 Subject: [PATCH 2/2] Respect the print_outp param inside Behat2 renderer --- features/behat2_renderer.feature | 260 +++++++++++++++----------- features/bootstrap/FeatureContext.php | 12 ++ src/Renderer/Behat2Renderer.php | 8 +- 3 files changed, 168 insertions(+), 112 deletions(-) diff --git a/features/behat2_renderer.feature b/features/behat2_renderer.feature index 7d1966c..1a2262f 100644 --- a/features/behat2_renderer.feature +++ b/features/behat2_renderer.feature @@ -1,115 +1,157 @@ - Feature: Behat2 Renderer +Feature: Behat2 Renderer - Background: - Given a file named "behat.yml" with: - """ - default: - formatters: - html: - output_path: %paths.base%/build - extensions: - emuse\BehatHTMLFormatter\BehatHTMLFormatterExtension: - name: html - renderer: Behat2 - file_name: Index - print_args: true - print_outp: true - loop_break: true - suites: - suite1: - paths: [ "%paths.base%/features/suite1" ] - suite2: - paths: [ "%paths.base%/features/suite2" ] - suite3: - paths: [ "%paths.base%/features/suite3" ] - """ - Given a file named "features/bootstrap/FeatureContext.php" with: - """ - + 3 features ( 1 success 2 fail ) +

+

+ 7 scenarios ( 2 success 5 fail ) +

+

+ 9 steps ( 4 success 3 pending 2 fail ) +

+ """ + And report file should contain: + """ + I am a passing step + """ + And report file should contain: + """ + I am a failing step + """ - """ - And report file for Behat2 should exists - And report file should contain: - """ -

- 3 features ( 1 success 2 fail ) -

-

- 7 scenarios ( 2 success 5 fail ) -

-

- 9 steps ( 4 success 3 pending 2 fail ) -

- """ - And report file should contain: - """ - I am a passing step - """ - And report file should contain: - """ - I am a failing step - """ +Scenario: Make sure we respect if a user does not want to print output + Given a file named "behat.yml" with: + """ + default: + formatters: + html: + output_path: %paths.base%/build + extensions: + emuse\BehatHTMLFormatter\BehatHTMLFormatterExtension: + name: html + renderer: Behat2 + file_name: Index + print_args: true + print_outp: false + loop_break: true + suites: + suite1: + paths: [ "%paths.base%/features/suite1" ] + suite2: + paths: [ "%paths.base%/features/suite2" ] + suite3: + paths: [ "%paths.base%/features/suite3" ] + """ + And a file named "features/suite1/suite_passing_failing.feature" with: + """ + Feature: Suite failing with passing scenarios + Scenario: Passing scenario + Given I give a passing step + Scenario: One Failing step + Given I give a failing step + """ + When I run "behat --no-colors" + Then report file for Behat2 should exists + And report file should not contain: + """ + I am a passing step + """ + And report file should contain: + """ + I am a failing step + """ diff --git a/features/bootstrap/FeatureContext.php b/features/bootstrap/FeatureContext.php index 568c78b..af08109 100644 --- a/features/bootstrap/FeatureContext.php +++ b/features/bootstrap/FeatureContext.php @@ -365,6 +365,18 @@ public function reportFileShouldContain(PyStringNode $string) PHPUnit_Framework_Assert::assertContains($string->getRaw(), file_get_contents($index)); } + /** + * @Given report file should not contain: + * + * @param PyStringNode $string + */ + public function reportFileShouldNotContain(PyStringNode $string) + { + $index = $this->reportDir . 'Index.html'; + + PHPUnit_Framework_Assert::assertNotContains($string->getRaw(), file_get_contents($index)); + } + private function getExitCode() { return $this->process->getExitCode(); diff --git a/src/Renderer/Behat2Renderer.php b/src/Renderer/Behat2Renderer.php index 9de4e8f..6b9f6b5 100644 --- a/src/Renderer/Behat2Renderer.php +++ b/src/Renderer/Behat2Renderer.php @@ -439,10 +439,12 @@ public function renderAfterStep($obj) } } - $output = $step->getOutput(); - if (!empty($output)) { - $print .= ' + if ($obj->getPrintOutputs() === true) { + $output = $step->getOutput(); + if (!empty($output)) { + $print .= '
'.$output.'
'; + } } $print .= '