2017 © Pedro Peláez
 

library behat-html-formatter

Creates an HTML report for Behat tests (enhanced version of emuse/behat-html-formatter)

image

roydude/behat-html-formatter

Creates an HTML report for Behat tests (enhanced version of emuse/behat-html-formatter)

  • Thursday, August 18, 2016
  • by roydude
  • Repository
  • 1 Watchers
  • 1 Stars
  • 1,542 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 79 Forks
  • 0 Open issues
  • 2 Versions
  • 17 % Grown

The README.md

BehatHtmlFormatterPlugin

Behat 3 extension for generating HTML reports from your test results (custom version of the original from emuse: https://github.com/dutchiexl/BehatHtmlFormatterPlugin). The changes I have made only relate to the Twig report (see below)., (*1)

Latest Stable Version Total Downloads Latest Unstable Version License, (*2)

Twig report

Twig Screenshot Twig Screenshot, (*3)

How?

  • The tool can be installed easily with composer.
  • Defining the formatter in the behat.yml file
  • Modifying the settings in the behat.ymlfile

Installation

Prerequisites

This extension requires:, (*4)

  • PHP 5.3.x or higher
  • Behat 3.x or higher

Through composer

The easiest way to keep your suite updated is to use Composer:, (*5)

Install with composer:

$ composer require --dev roydude/behat-html-formatter

Install using composer.json

Add BehatHtmlFormatterPlugin to the list of dependencies inside your composer.json., (*6)

{
    "require": {
        "behat/behat": "3.*@stable",
        "roydude/behat-html-formatter": "0.1.*",
    },
    "minimum-stability": "dev",
    "config": {
        "bin-dir": "bin/"
    }
}

Then simply install it with composer:, (*7)

$ composer install --dev --prefer-dist

You can read more about Composer on its official webpage., (*8)

Basic usage

Activate the extension by specifying its class in your behat.yml:, (*9)

# behat.yml
default:
  suites:
    ... # All your awesome suites come here

  formatters:
    html:
      output_path: %paths.base%/build/html/behat

  extensions:
    roydude\BehatHTMLFormatter\BehatHTMLFormatterExtension:
      name: html
      renderer: Twig
      file_name: index
      print_args: true
      print_outp: true
      loop_break: true

Configuration

  • Makeing (noreport) part of a test suit name will mean it's excuded from the report (handy for cache tests, for example, which aren't so interesting to business users who read the report).
  • output_path - The location where Behat will save the HTML reports. The path defined here is relative to %paths.base% and, when omitted, will be default set to the same path.
  • renderer - The engine that Behat will use for rendering, thus the types of report format Behat should output (multiple report formats are allowed, separate them by commas). Allowed values are:
    • Twig A new and modern report format based on Twig.
  • file_name - (Optional) Behat will use a fixed filename and overwrite the same file after each build. By default, Behat will create a new HTML file using a random name ("renderer name"_*"date hour"*).
  • print_args - (Optional) If set to true, Behat will add all arguments for each step to the report. (E.g. Tables).
  • print_outp - (Optional) If set to true, Behat will add the output of each step to the report. (E.g. Exceptions).
  • loop_break - (Optional) If set to true, Behat will add a separating break line after each execution when printing Scenario Outlines.

Blocked tests

To mark a test as skipped make sure it exits with PendingExcpetion, i.e.:, (*10)

throw new PendingException ("This scenario is blocked by bug MYPROJ-101");

Screenshot

The facility exists to embed a screenshot into test failures., (*11)

Currently png is the only supported image format., (*12)

In order to embed a screenshot, you will need to take a screenshot using your favourite webdriver and store it in the following filepath format:, (*13)

results/html/assets/screenshots/{{feature_name}}/{{scenario_name}}.png, (*14)

The feature_name and scenario_name variables will need to be the relevant item names without spaces., (*15)

Below is an example of FeatureContext methods which will produce an image file in the above format:, (*16)


/** * @BeforeScenario * * @param BeforeScenarioScope $scope * */ public function setUpTestEnvironment($scope) { $this->currentScenario = $scope->getScenario(); } /** * @AfterStep * * @param AfterStepScope $scope */ public function afterStep($scope) { //if test has failed, and is not an api test, get screenshot if(!$scope->getTestResult()->isPassed()) { //create filename string $featureFolder = str_replace(' ', '', $scope->getFeature()->getTitle()); $scenarioName = $this->currentScenario->getTitle(); $fileName = str_replace(' ', '', $scenarioName) . '.png'; //create screenshots directory if it doesn't exist if (!file_exists('results/html/assets/screenshots/' . $featureFolder)) { mkdir('results/html/assets/screenshots/' . $featureFolder); } //take screenshot and save as the previously defined filename $this->driver->takeScreenshot('results/html/assets/screenshots/' . $featureFolder . '/' . $fileName); } }

Note that the currentScenario variable will need to be at class level and generated in the @BeforeScenario method as Behat does not currently support obtaining the current Scenario in the @AfterStep method, where the screenshot is generated, (*17)

Issue Submission

When you need additional support or you discover something strange, feel free to Create a new issue., (*18)

License and Authors

Authors: https://github.com/roydude/BehatHtmlFormatterPlugin/contributors, (*19)

To do

  • Consider adding buttons for Skipped and Undefined.
  • Simplify screenshots.

The Versions

18/08 2016

dev-master

9999999-dev

Creates an HTML report for Behat tests (enhanced version of emuse/behat-html-formatter)

  Sources   Download

The Requires

 

The Development Requires

by Roy Collings

27/05 2015

v0.1.0

0.1.0.0

This will create a html formatter for Behat.

  Sources   Download

The Requires

 

by Neal Vanmeert