Skip to content

Commit

Permalink
Merge pull request #14 from lmrafael/master
Browse files Browse the repository at this point in the history
Added option to print the step arguments (Table Node) on the report.
  • Loading branch information
dutchiexl committed May 6, 2015
2 parents f3bcf07 + e861818 commit 0597412
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 8 deletions.
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ formatters:
name: html
renderer: Twig,Behat2
file_name: Index
print_table: true
</pre>

The *output* parameter is relative to %paths.base% and, when omitted, will default to that same path.
Expand All @@ -24,6 +25,8 @@ The *renderer* is the renderer engine and the report format that you want to be

The *file_name* is optional. When it is added, the report name will be fixed instead fo generated, and this file will be overwritten with every build.

The *print_args* is optional. When it is added, the report will contain the arguments for each step if exists. (e.g. Tables)

Actually, there is 3 formats :

- **Twig** : new report format based on Twig, **requires Twig installed**
Expand All @@ -39,11 +42,10 @@ File names have this format : *"renderer name"*_*"date hour"*
To be done:
========================

1. Store previous runs --> Done
2. Add parameters for behat.yml file
3. Add bootstrap as dependency
4. clean up html report
5. Add out parameter
1. Add parameters for behat.yml file
2. Add bootstrap as dependency
3. clean up html report
4. Add out parameter

=========================

Expand Down
2 changes: 2 additions & 0 deletions src/BehatHTMLFormatterExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public function configure(ArrayNodeDefinition $builder) {
$builder->children()->scalarNode("name")->defaultValue("emusehtml");
$builder->children()->scalarNode("renderer")->defaultValue("behat2");
$builder->children()->scalarNode("file_name")->defaultValue("generated");
$builder->children()->scalarNode("print_args")->defaultValue("false");
$builder->children()->scalarNode('output')->defaultValue('.');
}

Expand All @@ -68,6 +69,7 @@ public function load(ContainerBuilder $container, array $config) {
$definition->addArgument($config['name']);
$definition->addArgument($config['renderer']);
$definition->addArgument($config['file_name']);
$definition->addArgument($config['print_args']);

$definition->addArgument('%paths.base%');
$container->setDefinition("html.formatter", $definition)
Expand Down
19 changes: 17 additions & 2 deletions src/Formatter/BehatHTMLFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ class BehatHTMLFormatter implements Formatter {
*/
private $renderer;

/**
* Flag used by this Formatter
* @param $print_args boolean
*/
private $print_args;

/**
* @var Array
*/
Expand Down Expand Up @@ -147,13 +153,13 @@ class BehatHTMLFormatter implements Formatter {
* @param $name
* @param $base_path
*/
function __construct($name, $renderer, $filename, $base_path) {
function __construct($name, $renderer, $filename, $print_args, $base_path) {
$this->name = $name;
$this->print_args = $print_args;
$this->renderer = new BaseRenderer($renderer, $base_path);
$this->printer = new FileOutputPrinter($this->renderer->getNameList(), $filename, $base_path);
$this->timer = new Timer();
$this->memory = new Memory();

}

/**
Expand Down Expand Up @@ -267,6 +273,15 @@ public function getOutputPath() {
return $this->outputPath;
}

/**
* Returns if it should print the step arguments
*
* @return boolean
*/
public function getPrintArguments() {
return $this->print_args;
}

public function getTimer() {
return $this->timer;
}
Expand Down
1 change: 1 addition & 0 deletions src/Renderer/TwigRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public function renderAfterExercise($obj) {
'passedSteps' => $obj->getPassedSteps(),
'failedFeatures' => $obj->getFailedFeatures(),
'passedFeatures' => $obj->getPassedFeatures(),
'printStepArgs' => $obj->getPrintArguments(),
)
);

Expand Down
7 changes: 6 additions & 1 deletion templates/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,15 @@
{% for step in scenario.steps %}
<li class="list-group-item alert alert-{% if step.isPassed %}success{% elseif step.isSkipped %}info{% elseif step.isPending %}warning{% else %}danger{% endif %}">
<b>{{ step.keyword }}</b> {{ step.text }}
{% if printStepArgs is not null %}
{% for argument in step.arguments %}
<p style="padding-left:0.5em; overflow-x:scroll; white-space:nowrap; font-family:monospace">{{ argument | nl2br }}</p>
{% endfor %}
{% endif %}
{% if step.exception is not null %}
<br>
<p style="padding-left:2em ; color:gray">({{ step.exception }})</p>
{% endif %}
{% endif %}
</li>
{#<div class="bs-callout bs-callout-{% if step.passed %}success{% else %}danger{% endif %}" id="callout-collapse-accessibility">#}
{#<b>{{ step.keyword }}</b> {{ step.text }}#}
Expand Down

0 comments on commit 0597412

Please sign in to comment.