How To Generate Cucumber Test Report

2 min read

This is a continuation of test automation with selenium and cucumber.
Cucumber test reports are generated when cucumber is used to run your test scripts. The reports are created in a JSON format and stored in the directory you specify for it. We will use cucumber-html-reporter to convert the JSON report to a HTML file and launch it in a browser, for readability purpose.
To get started, install the reporter package

$ npm install cucumber-html-reporter -D

Now, create a directory generate-reports in the test root directory. Create index.js file in it and add this script

const reporter = require('cucumber-html-reporter');
const options = {
  theme: 'bootstrap',
  jsonFile: 'e2e-test-reports/cucumber_report.json',
  output: 'e2e-test-reports/cucumber_report.html',
  reportSuiteAsScenarios: true,
  scenarioTimestamp: true,
  launchReport: true,
  storeScreenshots: true,
  screenshotsDirectory: 'e2e-test-reports/screenshots/',
  metadata: {
    'App Version': '2020.02.22',
    Parallel: 'Scenarios',
    Executed: 'Remote'
  }
};

reporter.generate(options);

Ensure the report folder is existing in your project root directory before running tests. At this time, we should expect our file structure and package.json like this

├── node_modules
│
├── e2e-test-reports
│
├── e2e
│   ├── features
│   │   ├── step_definitions
│   │   │   ├── page.js
│   │   │
│   │   ├── support
│   │   │   ├── world.js
│   │   │   ├── hooks.js
│   │   │
│   │   ├── page.feature
│   │
│   ├── generate-reports
│   │   ├── index.js
│
├── package.json

package.json

{
  "name": "e2e",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "e2e-test": "cucumber-js e2e --format json:e2e-test-reports/cucumber_report.json",
    "e2e-test-report": "node e2e/generate-reports"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "chromedriver": "^80.0.1",
    "cucumber": "^6.0.5",
    "cucumber-html-reporter": "^5.0.2",
    "expect": "^24.9.0",
    "geckodriver": "^1.19.1",
    "selenium-webdriver": "^4.0.0-alpha.5"
  }
}

📅 22-02-2020