Search code examples
node.jsprotractorcucumbercucumberjs

The html report is not generated after the tests have finished, even though the json files are generated correctly in Protractor


I am using protractor with typescript to test a web page and i am trying to create a cucumber report with the package "cucumber-html-reporter" and the json is generated but the report doesn't.

Cucumberconfig.ts is :

   import { Config } from 'protractor';
import * as reporter from "cucumber-html-reporter";
export let config: Config = {
    directConnect: true,//Running chrome
    // seleniumAddress: 'http://localhost:4444/wd/hub',
    capabilities: {
        'browserName': 'chrome'
    },
    framework: 'custom',
    frameworkPath: require.resolve('protractor-cucumber-framework'),
  //  "types": ["chai", "cucumber", "node"],
    specs: ['../Features/*.feature'],
    cucumberOpts: {
        format:'json:./cucumber_report.json',
        onComplete: () =>{
            var reporter = require('cucumber-html-reporter');
            var options = {

                theme: 'bootstrap',
                jsonFile: './cucumber_report.json',
                output: './cucumber_report.html',
                scenarioTimestamp: true,
                reportSuiteAsScenarios: 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"
                },
             
            };

            reporter.generate(options);
        },
        require: [
            '../JSFiles/stepDefinitions/*.js' // accepts a glob
        ]
    },
}

And the output of the terminal is (successfully completed):

protractor cucumberconfig.js Debugger listening on ws://127.0.0.1:53501/eb7df2a4-ecc9-4d9a-8d9c-4786928a7288 For help, see: https://nodejs.org/en/docs/inspector Debugger attached. [16:00:32] I/launcher - Running 1 instances of WebDriver [16:00:32] I/direct - Using ChromeDriver directly...

DevTools listening on ws://127.0.0.1:53511/devtools/browser/bc06c50e-96ec-42fb-90ba-516608127bb4 ....test completado ......test completado ......test completado ..

3 scenarios (3 passed) 9 steps (9 passed) 0m13.468s [16:00:52] I/launcher - 0 instance(s) of WebDriver still running [16:00:52] I/launcher - chrome #01 passed Waiting for the debugger to disconnect...

This is the package.json:

{
  "name": "project",
  "version": "1.0.0",
  "description": "Project one",
  "main": "index.js",
  "scripts": {
    "test": "protractor JSFiles/cucumberconfig.js",
    "pretest": "tsc",
    "protractor": "./node_modules/protractor/built/cli.js",
    "webdriver-update": "./node_modules/.bin/webdriver-manager update"
  },
  "author": "Carol",
  "license": "ISC",
  "dependencies": {
    "@types/cucumber": "^6.0.1",
    "@types/jasmine": "^3.5.11",
    "@types/jasminewd2": "2.0.8",
    "@types/node": "^14.0.13",
    "chai": "^4.2.0",
    "chai-as-promised": "^7.1.1",
    "cucumber": "^6.0.5",
    "cucumber-html-report": "^0.6.5",
    "jasmine": "~3.5.0",
    "protractor-cucumber-framework": "^6.2.1",
    "ts-node": "8.10.2",
    "typescript": "~3.9.5"
  },
  "devDependencies": {
    "cucumber-html-reporter": "^5.2.0",
    "protractor": "^7.0.0"
  }
}

Could someone help me?

Thank you in advance.

enter image description here


Solution

  • You placed onComplete in the wrong place. It should belong to the config itself, not to cucumberOpts

    I can't give you a working solution, because you didn't attach the config in text format