Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Behat2 renderer supports step config parameter "print_outp" #137

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
157 changes: 157 additions & 0 deletions features/behat2_renderer.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
Feature: Behat2 Renderer

Background:
Given a file named "features/bootstrap/FeatureContext.php" with:
"""
<?php
use Behat\Behat\Context\CustomSnippetAcceptingContext,
Behat\Behat\Tester\Exception\PendingException;
class FeatureContext implements CustomSnippetAcceptingContext
{
public static function getAcceptedSnippetType() { return 'regex'; }
/** @When /^I give a passing step$/ */
public function passingStep() {
print_r("I am a passing step");
PHPUnit_Framework_Assert::assertEquals(2, 2);
}
/** @When /^I give a failing step$/ */
public function failingStep() {
PHPUnit_Framework_Assert::assertEquals(1, 2, 'I am a failing step');
}
/** * @When /^I give a pending step$/ */
public function somethingNotDoneYet() {
throw new PendingException();
}
}
"""

Scenario: Multiple Suites with multiple results, making sure we output results
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" ]
"""
And a file named "features/suite1/suite_failing_with_passing.feature" with:
"""
Feature: Suite failing with passing scenarios
Scenario: Passing scenario
Then I give a passing step
Scenario: One Failing step
Then I give a failing step
Scenario: One Pending step
Then I give a pending step
Scenario: Passing and Pending steps
Then I give a passing step
Then I give a pending step
Scenario: Passing and Failing steps
Then I give a passing step
Then I give a failing step
"""
And a file named "features/suite2/suite_passing.feature" with:
"""
Feature: Suite passing
Scenario: Passing scenario
Then I give a passing step
"""
And a file named "features/suite3/suite_pending.feature" with:
"""
Feature: Suite with pending scenario
Scenario: One pending step
Then I give a pending step
"""
When I run "behat --no-colors"
Then process output should be:
"""

--- FeatureContext has missing steps. Define them with these snippets:

/**
* @Then /^I give a pending step$/
*/
public function iGiveAPendingStep()
{
throw new PendingException();
}


"""
And report file for Behat2 should exists
And report file should contain:
"""
<p class="features">
3 features ( <strong class="passed">1 success</strong> <strong class="failed">2 fail</strong> )
</p>
<p class="scenarios">
7 scenarios ( <strong class="passed">2 success</strong> <strong class="failed">5 fail</strong> )
</p>
<p class="steps">
9 steps ( <strong class="passed">4 success</strong> <strong class="pending">3 pending</strong> <strong class="failed">2 fail</strong> )
</p>
"""
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
"""
29 changes: 22 additions & 7 deletions features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion features/twig_renderer.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions src/Renderer/Behat2Renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,15 @@ public function renderAfterStep($obj)
$print .= '<a href="'.$scenario->getRelativeScreenshotPath().'">Screenshot</a>';
}
}

if ($obj->getPrintOutputs() === true) {
$output = $step->getOutput();
if (!empty($output)) {
$print .= '
<pre class="backtrace">'.$output.'</pre>';
}
}

$print .= '
</li>';

Expand Down