Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

cucumber-html-reporter

gkushang1.4mMIT7.2.0TypeScript support: included

Generates Cucumber HTML reports in three different themes

cucumber, html, cucumber-html-reporter, html report, json to html

readme

cucumber-html-reporter

Generate Cucumber HTML reports with pie charts

Build Status npm Code Climate License contributors

Available HTML themes: ['bootstrap', 'hierarchy', 'foundation', 'simple']

Preview of HTML Reports

Provide Cucumber JSON report file created from your framework and this module will create pretty HTML reports. Choose your best suitable HTML theme and dashboard on your CI with available HTML reporter plugins.

  1. Bootstrap Theme Reports with Pie Chart
  2. Hierarchical Feature Structure Theme Reports With Pie Chart
  3. Foundation Theme Reports
  4. Simple Theme Reports

Snapshot of Bootstrap Report

Alt text

More snapshots are availble here

Install

npm install cucumber-html-reporter --save-dev

Notes:

Usage

Let's get you started:

  1. Install the package through npm or yarn
  2. Create an index.js and specify the options. Example of bootstrap theme:

var reporter = require('cucumber-html-reporter');

var options = {
        theme: 'bootstrap',
        jsonFile: 'test/report/cucumber_report.json',
        output: 'test/report/cucumber_report.html',
        reportSuiteAsScenarios: true,
        scenarioTimestamp: true,
        launchReport: true,
        metadata: {
            "App Version":"0.3.2",
            "Test Environment": "STAGING",
            "Browser": "Chrome  54.0.2840.98",
            "Platform": "Windows 10",
            "Parallel": "Scenarios",
            "Executed": "Remote"
        },
        failedSummaryReport: true,
    };

    reporter.generate(options);


    //more info on `metadata` is available in `options` section below.

    //to generate consodilated report from multi-cucumber JSON files, please use `jsonDir` option instead of `jsonFile`. More info is available in `options` section below.

Please look at the Options section below for more options

  1. Run the above code in a node.js script after Cucumber execution:
    node index.js

For CucumberJS

This module converts Cucumber's JSON format to HTML reports.

The code has to be separated from CucumberJS execution (after it).

In order to generate JSON formats, run the Cucumber to create the JSON format and pass the file name to the formatter as shown below,

$ cucumberjs test/features/ -f json:test/report/cucumber_report.json

Multiple formatter are also supported,

$ cucumberjs test/features/ -f summary -f json:test/report/cucumber_report.json

Are you using cucumber with other frameworks or running cucumber-parallel? Pass relative path of JSON file to the options as shown here

Options

theme

Available: ['bootstrap', 'hierarchy', 'foundation', 'simple'] Type: String

Select the Theme for HTML report.

N.B: Hierarchy theme is best suitable if your features are organized under features-folder hierarchy. Each folder will be rendered as a HTML Tab. It supports up to 3-level of nested folder hierarchy structure.

jsonFile

Type: String

Provide path of the Cucumber JSON format file

jsonDir

Type: String

If you have more than one cucumber JSON files, provide the path of JSON directory. This module will create consolidated report of all Cucumber JSON files.

e.g. jsonDir: 'test/reports' //where reports directory contains valid *.json files

N.B.: jsonFile takes precedence over jsonDir. We recommend to use either jsonFile or jsonDir option.

output

Type: String

Provide HTML output file path and name

reportSuiteAsScenarios

Type: Boolean Supported in the Bootstrap theme.

true: Reports total number of passed/failed scenarios as HEADER.

false: Reports total number of passed/failed features as HEADER.

launchReport

Type: Boolean

Automatically launch HTML report at the end of test suite

true: Launch HTML report in the default browser

false: Do not launch HTML report at the end of test suite

ignoreBadJsonFile

Type: Boolean

Report any bad json files found during merging json files from directory option.

true: ignore any bad json files found and continue with remaining files to merge.

false: Default option. Fail report generation if any bad files found during merge.

name

Type: String (optional)

Custom project name. If not passed, module reads the name from projects package.json which is preferable.

brandTitle

Type: String (optional)

Brand Title is the brand of your report, e.g. Smoke Tests Report, Acceptance Test Report etc as per your need. If not passed, it will be displayed as "Cucumberjs Report"

columnLayout

Available: [1, 2] Type: Number Default: 2

Select the Column Layout. One column or Two columns

1 = One Column layout (col-xx-12) 2 = Two Columns Layout (col-xx-6)

storeScreenshots

Type: Boolean Default: undefined

true: Stores the screenShots to the default directory. It creates a directory 'screenshot' if does not exists.

false or undefined : Does not store screenShots but attaches screenShots as a step-inline images to HTML report

screenshotsDirectory

Type: String (optional) Default: options.output/../screenshots

Applicable if storeScreenshots=true. Relative path for directory where screenshots should be saved. E.g. the below options should store the screenshots to the <parentDirectory>/screenshots/ where as the report would be at <parentDirectory>/report/cucumber_report.html

{
   ...
   ...
   output: '/report/cucumber_report.html',
   screenshotsDirectory: 'screenshots/',
   storeScreenshots: true
}

noInlineScreenshots

Type: Boolean Default: undefined

true: Applicable if storeScreenshots=true. Avoids inlining screenshots, uses relative path to screenshots instead (i.e. enables lazy loading of images).

false or undefined: Keeps screenshots inlined.

scenarioTimestamp

Type: Boolean Default: undefined

true: Applicable if theme: 'bootstrap'. Shows the starting timestamp of each scenario within the title.

false or undefined: Does not show starting timestamp.

metadata

Type: JSON (optional) Default: undefined

Print more data to your report, such as browser info, platform, app info, environments etc. Data can be passed as JSON key-value pair. Reporter will parse the JSON and will show the Key-Value under Metadata section on HTML report. Checkout the below preview HTML Report with Metadata.

Pass the Key-Value pair as per your need, as shown in below example,


 metadata: {
        "App Version":"0.3.2",
        "Test Environment": "STAGING",
        "Browser": "Chrome  54.0.2840.98",
        "Platform": "Windows 10",
        "Parallel": "Scenarios",
        "Executed": "Remote"
      }

failedSummaryReport

Type: Boolean

A summary report of all failed scenarios will be listed in a grid, which its scenario title, tags, failed step and exception.

true: Insert failed summary report.

false: Failed summary report will not be inserted.

Tips

Attach Screenshots to HTML report

Capture and Attach screenshots to the Cucumber Scenario and HTML report will render the screenshot image

for Cucumber V8


  let world = this;

  return driver.takeScreenshot().then((screenShot) => {
      // screenShot is a base-64 encoded PNG
      world.attach(screenShot, 'image/png');
  });

for Cucumber V2 and V3


  var world = this;

  driver.takeScreenshot().then(function (buffer) {
    return world.attach(buffer, 'image/png');
  };

for Cucumber V1


  driver.takeScreenshot().then(function (buffer) {
    return scenario.attach(new Buffer(buffer, 'base64'), 'image/png');
  };

Attach Plain Text to HTML report

Attach plain-texts/data to HTML report to help debug/review the results


  scenario.attach('test data goes here');

Attach pretty JSON to HTML report

Attach JSON to HTML report


  scenario.attach(JSON.stringify(myJsonObject, undefined, 4));

Changelog

changelog

changelog

6.0.0 (Mar-02-2023)

  • upgraded to be compatible with cucumber v8.9.1
  • upgraded all other dependencies to their latest versions

5.1.0 (Dec-15-2019)

5.0.2 (Sept-03-2019)

  • Quick fix the Chalk dependency - move from devDependencies to dependencies

5.0.1 (Sept-02-2019)

  • Remove duplicate check condition PR#189 by @ncounter
  • Scenario timestamp and notes PR#190 by @ncounter
  • Fixed regression of 4.0.4, fixes ISSUE#160 PR#191 @eiszfuchs
  • Bump lodash from 4.17.11 to 4.17.13 PR#193 by dependabot
  • Bump diff from 3.4.0 to 3.5.0 PR#194 by dependabot
  • Removed Deprecated, Update dependencies

5.0.0 (Apr-16-2019)

  • Fix data tables not being read in - PR#172
  • Update bootstrap to last 3.x stable version - PR#170
  • Check if embeddings are base64 encoded (even text/plain) - PR#164

4.0.3 (Feb-21-2019)

4.0.4

4.0.3 (Aug-23-2018)

  • Cannot generate report due an error with Trim() - PR#125
  • if to switch statement change #155 - PR#155

4.0.2 (Feb-26-2018)

  • Add support for configuring callback - PR#135

4.0.1 (Feb-06-2018)

  • Support to attach Video files as text/html to the report - PR#132

4.0.0 (Feb-02-2018)

  • Support for Cucumber 4. Duration is now in Nanoseconds.
  • Fix issue: #130

3.0.4 (Sep-20-2017)

  • Fix for Cucumber V2, mime_type

3.0.3 (Sep-20-2017)

  • Update outdated dependencies PR#115

3.0.2 (Sep-20-2017)

  • Add Backward compatibility for Cucumber V2 and V3. Add styling to Keywords GWT on HTML Report PR#114

3.0.1 (Aug-23-2017)

  • Feature: update to simple theme report PR#106
  • Fix issues: #101, #98

3.0.0 (Aug-22-2017)

2.0.3 (Jul-17-2017)

  • Escape HTML on step name & fix

    and

    order for block 'scenario-container' PR#97. Resolve Issue #52

2.0.2 (Jul-10-2017)

  • Support scoped packages PR#93

  • Fix issue#85 with Screenshot attachments with Selenium 3 & Cucumber 2 PR#95

2.0.1 (Jul-07-2017)

  • Save screenshots into custom directory PR#88

  • Added support for JSON attachments PR#89

      Based on MIME type of the attachment. Payload is expected to be base64-encoded (this is based on the existing behaviour of the Cucumber Reports plugin for Jenkins).
  • Add tests for Save Screenshots & refactor PR#91

2.0.0 (Jun-09-2017)

Support for Cucumber 2
  • Cucumber 2 PR#81. Resolves Issues #73,#72, #61, #55

    • Duration is reported as Milliseconds
    • Attachments are now plain text without encoding
    • DRY the templates and HTML scripts
    • Run Travis-CI with Node@7
    • Disable the Strict mode to test pending/undefined steps scenarios
  • Use `cucumber-html-reporter@0.5.0` for < Cucumber@2

0.5.0 (Jun-01-2017)

Enhancement
  • Introducing new Template Hierarchy from the Proposal, PR#76 & PR#77
    • The idea is to render features under respective folder hierarchy. Best case when your features are organized under feature-folders.
  • Enhance the Step Duration. Instead of 0s, show 1ms.
  • Backward compatible

0.4.2 (Apr-27-2017)

Fix
  • Fix to show '0s' if timestamp is in nanoseconds

0.4.1 (Apr-27-2017)

Enhancement
  • Add brandTitle to display on report. Checkout README for more details.
Fix
  • Step duration time in html report always shows 0s Issue#61 PR#62
  • Should not count Before/After hooks if they are hidden Issue#63 PR#64

0.4.0 (Mar-24-2017)

  • Supports Node versions >0.12
Revert the change

0.3.9 (Mar-24-2017)

  • Supports Node versions <0.12
Fix
  • Remove support for fs-extra for backward compatibility to support Node versions <0.12

0.3.8 (Mar-23-2017)

Fix
  • Use fs-extra instead of node-fs PR#50
  • Make chai a dev dependency PR#51
  • Bootstrap template fixes PR#56
  • Fix Travis CI PR#57

0.3.7 (Dec-06-2016)

Fix

0.3.6 (Dec-06-2016)

Fix
  • Failure in Before hook should fail the Feature/Scenario, Add slice to rest of the scenario pie charts PR#44

0.3.5 (Nov-29-2016)

Enhancements
  • Colors
    • Making labels & colors consistent on report PR#42

0.3.4 (Nov-28-2016)

Enhancements
  • Step Duration
    • light gray the step duration to distinguish from the GWT Step description

0.3.3 (Nov-28-2016)

Enhancements
  • Ambiguous Steps
    • show ambiguous status on the pie-chart, features, scenarios and at steps level PR#40

0.3.2 (Nov-21-2016)

Enhancements
  • Show Metadata
    • additional info about your test environment, browser, platform, app version, mode of execution, stage, and so on. PR#39

0.3.1 (Nov-18-2016)

Enhancements
  • Adding latest Previews to the readme for all themes
  • Add more snapshots for the user's review

0.3.0 (Nov-18-2016)

  • Deprecate Store Screenshots
    • Deprecate the option to store screenshot to the disk by default. If you still want to Store a screenShot to the directory, you can pass an option storeScreenShots to the reporter.
Enhancements
  • Inline Screenshots
    • Add support for inline png screenshots, fix package.json lookup, Fix success log: PR#32
  • For backward compatibility, adds an option to store screenshot to a directory: PR#38
storeScreenShots

Type: Boolean Default: undefined

true: Stores all screenShots stores the screenShots to the default directory. It creates a directory 'screehshot' if does not exists. false or undefined : Does not store screenShots but attaches screenShots as a step-inline images to HTML report

Fixes

0.2.17 (Nov-17-2016)

Enhancements
  • Tags on Report
    • Display Tags on Feature & Scenarios: PR#35
  • Filter Repeated Tags
    • Filter Tags from Scenarios which is already displayed at Feature Level & add some styling to Tags PR#37

0.2.16 (Oct-07-2016)

Enhancements
  • Scenario Description
    • Show Scenario Description on HTML report: ISSUE#33

0.2.15 (Sep-28-2016)

Fix

0.2.14 (Sep-27-2016)

Enhancements
  • Option to add custom name to the project & adds footer: PR#28

0.2.13 (Sep-27-2016)

Enhancements
  • Show time taken by each steps to complete the execution on report: PR#17 & PR#27

0.2.12 (Sep-27-2016)

Fixes
  • Show hidden hooks if they fail: PR#25

0.2.11 (Sep-26-2016)

Fixes
  • Fix typo on README: PR#22

  • Fix Foundation template for local: PR#23

0.2.10 (Sep-22-2016)

Enhancements
  • Conditionally hide hidden steps from the report: PR#20

    • After & Before hooks are hidden on Cucumber JSON file. They will be visible on the report only if it has Info or Screenshot attached to it.

0.2.9 (Sep-08-2016)

Enhancements
  • Ignore the bad JSON files when consolidating from the JSON Directory: PR#13

    • Set the option ignoreBadJsonFile to true as a boolean to ignore the Bad JSON files
BugFix
  • Fixed the issue when report was breaking with the Cucumber's Doc String: Issue#14

0.2.8 (Aug-30-2016)

Enhancements
  • Generate consolidated report from multiple JSON files: PR#12

    • Provide the path of jsonDir to generate consolidated report,

var reporter = require('cucumber-html-reporter');
...
...

var options = {
        theme: 'bootstrap',
        jsonDir: 'test/reports',
        output: 'test/report/cucumber_report.html',
        reportSuiteAsScenarios: true,
        launchReport: true
    };

    reporter.generate(options);

0.2.7 (Aug-16-2016)

Enhancements
  • Launch report automatically after test ends
  • Pass a flag launchReport to the options

var reporter = require('cucumber-html-reporter');
...
...

var options = {
        theme: 'bootstrap',
        jsonFile: 'test/report/cucumber_report.json',
        output: 'test/report/cucumber_report.html',
        reportSuiteAsScenarios: true,
        launchReport: true
    };

    reporter.generate(options);

0.2.6 (Jul-29-2016)

BugFix
  • Fixed the issue where Error messages were not printing on the report.

0.2.5 (Jul-28-2016)

Enhancements
  • trim the text to be printed on report

0.2.4 (Jul-28-2016)

BugFix

0.2.3 (Jul-26-2016)

Enhancements

0.2.2 (Jul-21-2016)

BugFix

0.2.1 (Jul-12-2016)

Enhancements
  • Recursively create HTML report directory if does not exists
  • Remove outdated chai-fs depedency and use chai-should assertions
  • Lighter the background color or Scenario attachments

0.2.0 (Jul-10-2016)

Support for Cucumber@1.2.0 version

0.1.6 (Jul-07-2016)

Enhancements
  • Format feature descriptions on report
  • Add overflow scroll bar for the bigger data-table
  • print error messaged in the pre

0.1.5 (Jul-05-2016)

Enhancements
  • Show feature description on report

  • Updated README

Bug fixes
  • Fix bug when cucumber error message has kind of html tags as a string, e.g. <object> is not defined.

0.1.4 (Jun-28-2016)

Enhancements
  • Using path instead of separators to make platform agnostic

  • Updated tests hooks

  • README updated with the instructions on how to integrate reporter to the cucumber hooks

0.1.3 (Jun-27-2016)

Bug fixes
  • Fixed a bug in template path

  • README updated

0.1.1 (Jun-27-2016)

New Features
  • Tooltip for Scenarios or Features in the HEADER based on reportSuiteAsScenarios flag

  • Add an optional callback for the generate(options, callback) function

  • Report pending steps in scenarios for bootstrap & foundation themes

  • Refactored and added more tests & validations