PHPackages                             emuse/behat-html-formatter - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. emuse/behat-html-formatter

ActiveLibrary[Testing &amp; Quality](/categories/testing)

emuse/behat-html-formatter
==========================

This will create a html formatter for Behat.

v2.0.0(3y ago)1122.6M↓40.7%117[35 issues](https://github.com/dutchiexl/BehatHtmlFormatterPlugin/issues)[3 PRs](https://github.com/dutchiexl/BehatHtmlFormatterPlugin/pulls)15MITPHPPHP &gt;=5.3.0CI failing

Since May 27Pushed 2y ago16 watchersCompare

[ Source](https://github.com/dutchiexl/BehatHtmlFormatterPlugin)[ Packagist](https://packagist.org/packages/emuse/behat-html-formatter)[ RSS](/packages/emuse-behat-html-formatter/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (1)Dependencies (5)Versions (8)Used By (15)

BehatHtmlFormatterPlugin
------------------------

[](#behathtmlformatterplugin)

Behat 3 extension for generating HTML reports from your test results.

[![Latest Stable Version](https://camo.githubusercontent.com/b624f3d8b65df721b33d2d608107ea9d0d0dffd9c294d70e75148f2d2b8e053a/68747470733a2f2f706f7365722e707567782e6f72672f656d7573652f62656861742d68746d6c2d666f726d61747465722f762f737461626c65)](https://packagist.org/packages/emuse/behat-html-formatter) [![Total Downloads](https://camo.githubusercontent.com/a2c14bf21b8ff4e9883967299db67599ae2134ae633ff1303a875c6bbea51d30/68747470733a2f2f706f7365722e707567782e6f72672f656d7573652f62656861742d68746d6c2d666f726d61747465722f646f776e6c6f616473)](https://packagist.org/packages/emuse/behat-html-formatter) [![Latest Unstable Version](https://camo.githubusercontent.com/d60b72aa191247119e269033f6dffb1aac4e390da0dad8f8c40b6fb2eaaa600a/68747470733a2f2f706f7365722e707567782e6f72672f656d7573652f62656861742d68746d6c2d666f726d61747465722f762f756e737461626c65)](https://packagist.org/packages/emuse/behat-html-formatter) [![License](https://camo.githubusercontent.com/4ccafe8fb0975cfdbda3d09c9596da813ad459067a4aa7cbbcbd0e8612675f49/68747470733a2f2f706f7365722e707567782e6f72672f656d7573652f62656861742d68746d6c2d666f726d61747465722f6c6963656e7365)](https://packagist.org/packages/emuse/behat-html-formatter)

### Twig report

[](#twig-report)

[![Twig Screenshot](https://camo.githubusercontent.com/0ef008d88774d969ed2f514f75e7879ee9e402699b7f4f81a741e0fe8cbe4ed3/687474703a2f2f692e696d6775722e636f6d2f6f307a437169422e706e67)](https://camo.githubusercontent.com/0ef008d88774d969ed2f514f75e7879ee9e402699b7f4f81a741e0fe8cbe4ed3/687474703a2f2f692e696d6775722e636f6d2f6f307a437169422e706e67)

### Behat 2 report

[](#behat-2-report)

[![Behat2 Screenshot](https://camo.githubusercontent.com/c5cc587370c2d3ecab4d808ab2d5e8a5e5c041db86ae48468d658088c94eb6fe/687474703a2f2f6935372e74696e797069632e636f6d2f323837673934322e6a7067)](https://camo.githubusercontent.com/c5cc587370c2d3ecab4d808ab2d5e8a5e5c041db86ae48468d658088c94eb6fe/687474703a2f2f6935372e74696e797069632e636f6d2f323837673934322e6a7067)

How?
----

[](#how)

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

Installation
------------

[](#installation)

### Prerequisites

[](#prerequisites)

This extension requires:

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

### Through composer

[](#through-composer)

The easiest way to keep your suite updated is to use [Composer](http://getcomposer.org%3E):

#### Install with composer:

[](#install-with-composer)

```
$ composer require --dev emuse/behat-html-formatter
```

#### Install using `composer.json`

[](#install-using-composerjson)

Add BehatHtmlFormatterPlugin to the list of dependencies inside your `composer.json`.

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

Then simply install it with composer:

```
$ composer install --dev --prefer-dist
```

You can read more about Composer on its [official webpage](http://getcomposer.org).

Basic usage
-----------

[](#basic-usage)

Activate the extension by specifying its class in your `behat.yml`:

```
# behat.yml
default:
  suites:
    default:
       contexts:
          - emuse\BehatHTMLFormatter\Context\ScreenshotContext:
               screenshotDir: build/html/behat/assets/screenshots
    ... # All your awesome suites come here
  formatters:
    html:
      output_path: %paths.base%/build/html/behat

  extensions:
    emuse\BehatHTMLFormatter\BehatHTMLFormatterExtension:
      name: html
      renderer: Twig,Behat2
      file_name: index
      print_args: true
      print_outp: true
      loop_break: true
```

### Command line options

[](#command-line-options)

Add the following to your behat command to print a report:

`behat --format html --out MYDIRECTORY`

Setting the format to html will output the various reports that you configure below (Behat2, Twig, Minimal, etc.)

You also need to specify the output directory for the reports as MYDIRECTORY.

Configuration
-------------

[](#configuration)

### Formatter configuration

[](#formatter-configuration)

- `output_path` - The location where Behat will save the HTML reports. Use `%paths.base%` to build the full path.

### Extension configuration

[](#extension-configuration)

- `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:
- *Behat2* for generating HTML reports like they were generated in Behat 2.
- *Twig* A new and more modern format based on Twig.
- *Minimal* An ultra minimal HTML output.
- `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.

Screenshot
----------

[](#screenshot)

The facility exists to embed a screenshot into test failures.

Currently png is the only supported image format.

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:

results/html/assets/screenshots/{{feature\_name}}/{{scenario\_name}}.png

The feature\_name and scenario\_name variables will need to be the relevant item names without spaces.

Below is an example of FeatureContext methods which will produce an image file in the above format:

```
        /**
         * @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 = preg_replace('/\W/', '', $scope->getFeature()->getTitle());

                              $scenarioName = $this->currentScenario->getTitle();
                              $fileName = preg_replace('/\W/', '', $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);
                // For Selenium2 Driver you can use:
                // file_put_contents('results/html/assets/screenshots/' . $featureFolder . '/' . $fileName, $this->getSession()->getDriver()->getScreenshot());
            }
        }
```

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

Issue Submission
----------------

[](#issue-submission)

When you need additional support or you discover something *strange*, feel free to [Create a new issue](https://github.com/dutchiexl/BehatHtmlFormatterPlugin/issues/new).

License and Authors
-------------------

[](#license-and-authors)

Authors:

###  Health Score

46

—

FairBetter than 92% of packages

Maintenance14

Infrequent updates — may be unmaintained

Popularity59

Moderate usage in the ecosystem

Community41

Growing community involvement

Maturity63

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~571 days

Recently: every ~339 days

Total

6

Last Release

1176d ago

Major Versions

v0.2.0 → 1.0.x-dev2021-07-14

v1.0.0 → 2.0.x-dev2023-03-21

### Community

Maintainers

![](https://www.gravatar.com/avatar/8094cc4ca0dbd89d6135f4e8a68cb68c47b31bbdc7ab5c5ca2924b8570bd94fa?d=identicon)[dutchiexl](/maintainers/dutchiexl)

---

Top Contributors

[![dutchiexl](https://avatars.githubusercontent.com/u/4411566?v=4)](https://github.com/dutchiexl "dutchiexl (55 commits)")[![lmrafael](https://avatars.githubusercontent.com/u/2047805?v=4)](https://github.com/lmrafael "lmrafael (16 commits)")[![kwisatz](https://avatars.githubusercontent.com/u/237949?v=4)](https://github.com/kwisatz "kwisatz (10 commits)")[![PurHur](https://avatars.githubusercontent.com/u/5864315?v=4)](https://github.com/PurHur "PurHur (7 commits)")[![kuczek](https://avatars.githubusercontent.com/u/2432505?v=4)](https://github.com/kuczek "kuczek (6 commits)")[![cckakhandki](https://avatars.githubusercontent.com/u/13152468?v=4)](https://github.com/cckakhandki "cckakhandki (5 commits)")[![rdotter](https://avatars.githubusercontent.com/u/4062360?v=4)](https://github.com/rdotter "rdotter (5 commits)")[![legovaer](https://avatars.githubusercontent.com/u/5813212?v=4)](https://github.com/legovaer "legovaer (2 commits)")[![ich123](https://avatars.githubusercontent.com/u/419039?v=4)](https://github.com/ich123 "ich123 (2 commits)")[![throup](https://avatars.githubusercontent.com/u/1216362?v=4)](https://github.com/throup "throup (2 commits)")[![Evgenas](https://avatars.githubusercontent.com/u/2884742?v=4)](https://github.com/Evgenas "Evgenas (2 commits)")[![lchenay](https://avatars.githubusercontent.com/u/804687?v=4)](https://github.com/lchenay "lchenay (1 commits)")[![lopezs](https://avatars.githubusercontent.com/u/1067998?v=4)](https://github.com/lopezs "lopezs (1 commits)")[![pawel-grzona](https://avatars.githubusercontent.com/u/285337?v=4)](https://github.com/pawel-grzona "pawel-grzona (1 commits)")[![ptmkenny](https://avatars.githubusercontent.com/u/1451472?v=4)](https://github.com/ptmkenny "ptmkenny (1 commits)")[![rjb-dev](https://avatars.githubusercontent.com/u/16692687?v=4)](https://github.com/rjb-dev "rjb-dev (1 commits)")[![ajgarlag](https://avatars.githubusercontent.com/u/388184?v=4)](https://github.com/ajgarlag "ajgarlag (1 commits)")[![tikolakin](https://avatars.githubusercontent.com/u/5860505?v=4)](https://github.com/tikolakin "tikolakin (1 commits)")[![artberri](https://avatars.githubusercontent.com/u/454523?v=4)](https://github.com/artberri "artberri (1 commits)")[![Bersman](https://avatars.githubusercontent.com/u/1538239?v=4)](https://github.com/Bersman "Bersman (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/emuse-behat-html-formatter/health.svg)

```
[![Health](https://phpackages.com/badges/emuse-behat-html-formatter/health.svg)](https://phpackages.com/packages/emuse-behat-html-formatter)
```

###  Alternatives

[drupal/drupal-extension

Drupal extension for Behat

21215.5M166](/packages/drupal-drupal-extension)[wp-cli/wp-cli-tests

WP-CLI testing framework

423.0M129](/packages/wp-cli-wp-cli-tests)[drevops/behat-steps

Collection of steps for Behat

26409.9k4](/packages/drevops-behat-steps)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
