Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to parse cucumberjs output into json - error while generating the report with Cucumber-html-reporter #3

Open
ravim20051 opened this issue Oct 23, 2017 · 11 comments

Comments

@ravim20051
Copy link

I am trying to execute the test in Protractor and generate the results in JSON format and integrationg Cucumber-html-reporter to take this JSON as input and generate the HTML report with Bootstrap options. But Not sucessfull

Below is my config file:

var reporter = require('cucumber-html-reporter');
exports.config = {
seleniumAddress: 'http://172.17.205.173:4444/wd/hub',
seleniumSessionId: '1bcc031df0fa1a241b0fd06445af324d',

capabilities: {
'browserName': 'chrome'
},

specs: ['Login_ZRPE.js'],
resultJsonOutputFile:'G:/Protractor/ZPlatform_Script/protractor-reports/cucumber_report.json',

onComplete: function() {
var options = {
theme: 'bootstrap',
jsonFile: 'G:/Protractor/ZPlatform_Script/protractor-reports/cucumber_report.json',
output: 'G:/Protractor/ZPlatform_Script/protractor-reports/cucumber_report.html',
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);
}
};

Execute the above config file, Test executed successfully but while report generation the below error is displays. I have tried various options which is available in various forum but the below is not resolved. Please let me know how to solve this issue

Error:
1 spec, 0 failures
Finished in 11.412 seconds

Finished suite
Unable to parse cucumberjs output into json: 'G:/Protractor/ZPlatform_Script/protractor-reports/cucumber_report.json'
{ Error: G:/Protractor/ZPlatform_Script/protractor-reports/cucumber_report.json: ENOENT: no such file or directory, open 'G:\Protractor\ZPlatform_Script\protractor-reports\cucumber_r
eport.json'
at Object.fs.openSync (fs.js:653:18)
at Object.fs.readFileSync (fs.js:554:33)
at Object.readFileSync (C:\Users\zafin\AppData\Roaming\npm\node_modules\cucumber-html-reporter\node_modules\jsonfile\index.js:67:22)
at isValidJsonFile (C:\Users\zafin\AppData\Roaming\npm\node_modules\cucumber-html-reporter\lib\reporter.js:404:48)
at Object.generate (C:\Users\zafin\AppData\Roaming\npm\node_modules\cucumber-html-reporter\lib\reporter.js:426:9)
at Object.generateReport [as generate] (C:\Users\zafin\AppData\Roaming\npm\node_modules\cucumber-html-reporter\index.js:30:21)
at onComplete (G:\Protractor\ZPlatform_Script\config.js:37:14)
at C:\Users\zafin\AppData\Roaming\npm\node_modules\protractor\built\frameworks\jasmine.js:115:27
at module.exports.jasmineDone (C:\Users\zafin\AppData\Roaming\npm\node_modules\protractor\node_modules\jasmine\lib\reporters\completion_reporter.js:15:5)
at dispatch (C:\Users\zafin\AppData\Roaming\npm\node_modules\protractor\node_modules\jasmine-core\lib\jasmine-core\jasmine.js:4366:28)
errno: -4058,
code: 'ENOENT',
syscall: 'open',
path: 'G:\Protractor\ZPlatform_Script\protractor-reports\cucumber_report.json' }
[16:26:04] I/launcher - 0 instance(s) of WebDriver still running
[16:26:04] I/launcher - chrome #1 passed

@JesterXL
Copy link
Owner

JesterXL commented Nov 1, 2017

Interesting, ok. Do you have a copy oft he JSON it rendered? If you could send that, I can try to run locally to.

Also, can you use a relative path to see if it works? Instead of:

G:/Protractor/ZPlatform_Script/protractor-reports/cucumber_report.json

Try:

./cucumber_report.json

@vvedachalam
Copy link

I am also facing same issue.

Protractor.config.js

const path = require('path');
const argv = require('yargs').argv;
const Reporter = require('./e2e/support/reporter');
// const jsonReports = process.cwd() + '/reports/json';
const jsonReports = path.join(process.cwd(), "/reports/json");

exports.config = {
framework: 'custom',
frameworkPath: require.resolve('protractor-cucumber-framework'),
specs: getFeatureFiles(),
cucumberOpts: {
compiler: ['ts:ts-node/register'],
require: ['./e2e/**/.e2e-spec.ts', './e2e/support/.js'],
strict: true, // fail if there are any undefined or pending steps
format: 'json:./reports/json/cucumber_report.json',
dryRun: false, // invoke every formatter without executing steps
tags: ["~@ignore"], // <string[]> (expression) only execute the features or scenarios with tags matching the expression
},
onPrepare: function () {
require('ts-node').register({
project: 'e2e/tsconfig.e2e.json'
});
console.log(path.join(process.cwd(), "/reports/json"));
browser.manage().window().maximize();

// implicit and page load timeouts

browser.manage().timeouts().pageLoadTimeout(40000);
browser.manage().timeouts().implicitlyWait(5000);

Reporter.createDirectory(jsonReports);

},
onComplete: function () {
Reporter.createHTMLReport();
},
getPageTimeout: 60000,
allScriptsTimeout: 60000,
disableChecks: true,
useAllAngular2AppRoots: true
};

Reporter.js

const fs = require("fs");
const mkdirp = require("mkdirp");
const path = require("path");
const reporter = require("cucumber-html-reporter");
const report = require("cucumber-html-report");
// const htmlReports = process.cwd() + "/reports/html";
// const targetJson = process.cwd() + "/reports/json/cucumber_report.json";
const jsonReports = path.join(process.cwd(), "/reports/json");
const htmlReports = path.join(process.cwd(), "/reports/html");
const targetJson = path.join(jsonReports , "/cucumber_report.json");

const cucumberReportOptions = {
source: targetJson,
dest: htmlReports,
name: "cucumber_report.html",
title: "Cucumber Report"
};
const cucumberReporteroptions = {
theme: "bootstrap",
jsonFile: targetJson,
output: htmlReports + "/cucumber_reporter.html",
reportSuiteAsScenarios: true
};

class Reporter {

static createDirectory(dirName) {
//Check if the directory exist
if (!fs.existsSync(dirName)) {
mkdirp.sync(dirName);
}
}

/**

  • Create an html report output
    */
    static createHTMLReport() {
    try {
    reporter.generate(cucumberReporteroptions); //invoke cucumber-html-reporter
    report
    .create(cucumberReportOptions)
    .then(function () {
    console.log("cucumber_report.html created successfully!");
    })
    .catch(function (err) {
    if (err) {
    console.error(err);
    }
    });
    } catch (err) {
    if (err) {
    console.log("Failed to save cucumber test results to json file.");
    console.log(err);
    }
    }
    }

}

module.exports = Reporter;

ERROR:
Unable to parse cucumberjs output into json: 'C:\rc\E2E.Tests\ng\reports\json\cucumber_report.json' SyntaxError: C:\rc\E2E.Tests\ng\reports\json\cucumber_report.json: Unexpected end of JSON input
at JSON.parse ()
at Object.readFileSync (C:\rc\E2E.Tests\ng\node_modules\jsonfile\index.js:69:17)
Directory already exists: C:\rc\E2E.Tests\ng\reports\html
SyntaxError: Unexpected end of JSON input
at JSON.parse ()
at loadCucumberJson (C:\rc\E2E.Tests\ng\node_modules\cucumber-html-report\lib\report.js:276:15)
at exports.createReport (C:\rc\E2E.Tests\ng\node_modules\cucumber-html-report\lib\report.js:85:41)
at
at process._tickCallback (internal/process/next_tick.js:160:7)

@vvedachalam
Copy link

Just ignore me.. My json was empty.. should have checked that first :P

@srutikritee
Copy link

I am also getting the same issue:

Unable to parse cucumberjs output into json: 'reports/cucumber-report.json' SyntaxError: reports/cucumber-report.json: Unexpected end of JSON input.

Please help me to resolve this issue.

@aburra12
Copy link

Any solution to this problem? I am using cucumber-html-reporter too and stuck with this issue " Unable to parse cucumberjs output into json: '\e2e\reports\json\cucumber_report.json' { Error: \e2e\reports\json\cucumber_report.json: ENOENT: no such file or directory, open '\e2e\reports\json\cucumber_report.json'

@sumitroy2611
Copy link

I am facing the same issue. The thing which I could figure out from this is. Till the time we are expecting the html-reporter to read the updated report.json file and generate an Html report out of it, the cucumber-js process has not finished writing the test report. And hence, it fails to parse the file.

In my case, I am calling the report generation utility in Afterall hook. And running the tests in parallel. However, when I run the test in a single thread. Then this works fine and generates the report at the end of the execution

@akbarchandani
Copy link

I am facing the same issue. The thing which I could figure out from this is. Till the time we are expecting the html-reporter to read the updated report.json file and generate an Html report out of it, the cucumber-js process has not finished writing the test report. And hence, it fails to parse the file.

In my case, I am calling the report generation utility in Afterall hook. And running the tests in parallel. However, when I run the test in a single thread. Then this works fine and generates the report at the end of the execution

I am facing the same issue. Any solution to the problem?

@kalaiyarasanperumal
Copy link

kalaiyarasanperumal commented Nov 28, 2022

i am facing same

⚠️ 😞 Unable to parse cucumberjs output into json: '%s' cucumber_report.json SyntaxError: cucumber_report.json: Unexpected end of JSON input
image

error message will display before execution

image

image

before cucumbe-html-report beofore json file has not updated of base of current execution

@norbertorok92
Copy link

any update on this?

1 similar comment
@ashokkumar-sm
Copy link

any update on this?

@abhaysingh3GL
Copy link

Update the options to use html format, it should work

let options = [
'--require-module ts-node/register',
'--require ./steps/stepDef.steps.ts',
'--format progress',
'--format html:Reports/report.html',
'--format json:Reports/report.json'
].join(' ');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests