diff --git a/features/behat2_renderer.feature b/features/behat2_renderer.feature new file mode 100644 index 0000000..1a2262f --- /dev/null +++ b/features/behat2_renderer.feature @@ -0,0 +1,157 @@ +Feature: Behat2 Renderer + +Background: + 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 + """ + +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 4d137ea..af08109 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); @@ -362,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/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..6b9f6b5 100644 --- a/src/Renderer/Behat2Renderer.php +++ b/src/Renderer/Behat2Renderer.php @@ -438,6 +438,15 @@ public function renderAfterStep($obj) $print .= 'Screenshot'; } } + + if ($obj->getPrintOutputs() === true) { + $output = $step->getOutput(); + if (!empty($output)) { + $print .= ' +
'.$output.'
'; + } + } + $print .= ' ';