It is currently not possible to specify an "output" file as a CLI argument for saving reports. The JSON formatter seems to write directly to STDOUT, which can be a problem when debugging (using console.log) or if the program fails, producing invalid JSON.
It would be desirable if this worked like cucumber in ruby, allowing multiple formats saved out to separate output files.
There are actually two separate issues here:
I created a separate issue regarding the multiple formatters.
Julien is there any news on when we would be able to specify an HTML output file?
+1
+1
HI I have been manually copying and pasting the content of the JSON results to the cucumber.json file in the data directory of cucumber-json2report-master, which does allow me to get some nice results of the run, but it would be great if cucumber.js could place the file in that directory, thus eliminating the manual step.
I don't really want to hack the version or create a fork. Suggestions?
Any update on this?
@letshaveyer this sounds like a useful feature to you. Why don't you send a pull request?
Until this is working you can modify json_formatter.js. This is hack but much easier that copying an pasting every time. We also are adding a time stamp to the filename.
Change the formatterIo object to also write to a file
var formatterIo = {
write: function(string){
self.log(string);
fs.writeFileSync('path\test_results.json', string); // added
}
};
This is a simple thing to do with simple pipe redirects in unix and bash
cucumber-js --format=json | tee wow.json
+1 to close
We can't pipe it. We're using protractor's config file to set cucumberjs
options
CucumberOpts: {
Format: 'JSON',
Tags: '@testRun'
}
We have a bat file that uses node to start protractor.
Brad
On Aug 5, 2014 9:54 AM, "Sam Saccone" [email protected] wrote:
This is a simple thing to do with simple pipe redirects in unix
cucumber-js --format=json | tee wow.json
+1 to close
—
Reply to this email directly or view it on GitHub
https://github.com/cucumber/cucumber-js/issues/90#issuecomment-51199997.
Interesting @brad8118 this seems like it would be a feature of protractor and not cucumber.
protractor is invoking cucumber and what it does with the output is the responsibility of protractor and not cucumber.
Those are just my initial thoughts, open to ideas tho. I am just trying to prevent feature creep of the cucumber lib.
@brad8118 I am using protractor. I dosn't really want to muddle source code. Is there a way that I can add a hook or support file to do that?
var formatterIo = {
write: function(string){
self.log(string);
fs.writeFileSync('path\test_results.json', string); // added
}
};
@samccone protractor use native reporting depends which framework that you are using. If you are using Jasmine, it will use reporting in Jasmine. If you are using cucumber framework, it will use reporting in cucumber.js, which currently has no way to output a file.
@jlin412, I don't know how to pass / get the json that's being generated without changing cucumber.js.
I've also thought about the cleanup function in our protractor json config file. But it only passes 1 or 0.
// ----- The cleanup step -----
//
// A callback function called once the tests have finished running and
// the webdriver instance has been shut down. It is passed the exit code
// (0 if the tests passed or 1 if not).
onCleanUp: function () {}
Looks like this is already done in another fork. nicolassenechal@b337b18
@jlin412 when you cute and paste the json. What are you doing with it? Are you converting it into html?
@brad8118 I use redirection to send json output to a file from protractor and then I have grunt task function to filter out json format using regex match:
grunt.registerTask('jsonOutput', function () {
var testOutput = grunt.file.read('test/e2e/tmp/cucumberOutput.json');
var json = testOutput.match(/(\[\s+\{[\s\S]*\}\s+\]\s+\}\s+\]\s+\}\s+\])/)[1];
grunt.file.write('test/e2e/output/cucumberReport.json', json);
});
Then I use cucumber sandwich to convert to html (A java project).
http://www.farooqyousuf.net/2013/12/generating-reports-with-cucumber-sandwich/
I made slight modification to cucumber sandwich code base so I can call it on demand rather than depending on the file event listener.
Hi Guys, just trying to get my head around when this will be committed back to the cucumber-js Master? I need this functionality now, but I'm wary of relying on a forked branch. Could you give me an idea of when it will be available in cucumber-js master and just a quick idea of whether it's wise to rely on one of the forked branches in the meantime? Thanks, Fraser.
+1 -- I know I'm not alone in going through some crazy contortions to use cucumber with protractor when a flag to write to file would be sooo helpful. I don't understand why writing to a file is considered feature creep. Is cucumber only intended to allow developers to visually inspect the quality of their work? Are we not supposed to use cucumber within the scope of a larger test environment? This can't be so...
Hi,
Anyone can help me, i've not found how to configure properly json output into file.
I use gulp+protractor+cucumberjs
Thanks in advance
@cedriclombardot
There is a way to select a directory to json output from protractor from 1.5.0 though I haven't used it.
Currently, I added a hook so I can use pretty and json formatter together:
module.exports = function JsonOutputHook() {
var Cucumber = require('cucumber');
var JsonFormatter = Cucumber.Listener.JsonFormatter();
var fs = require('fs');
JsonFormatter.log = function (json) {
fs.writeFile('test/e2e/output/cucumberReport.json', json, function (err) {
if (err) throw err;
console.log('json file location: test/e2e/output/cucumberReport.json');
});
};
this.registerListener(JsonFormatter);
};
I've not seen the resultJsonOutputFile
seems to works magickly and ready
to go in xml with : https://www.npmjs.com/package/protractor-cucumber-junit
Cédric
2015-01-02 18:34 GMT+01:00 Jason Lin [email protected]:
@cedriclombardot https://github.com/cedriclombardot
There is a way to select a directory to json output from protractor from
1.5.0 though I haven't used it.
Currently, I added a hook so I can use pretty and json formatter together:module.exports = function JsonOutputHook() {
var Cucumber = require('cucumber');
var JsonFormatter = Cucumber.Listener.JsonFormatter();
var fs = require('fs');JsonFormatter.log = function (json) {
fs.writeFile('test/e2e/output/cucumberReport.json', json, function (err) {
if (err) throw err;
console.log('json file location: test/e2e/output/cucumberReport.json');
});
};this.registerListener(JsonFormatter);
};—
Reply to this email directly or view it on GitHub
https://github.com/cucumber/cucumber-js/issues/90#issuecomment-68544890.
+1
So could we please get an update on when this will get committed to master? I'm currently using cucumberjs minus protractor (or any other selenium style web test framework) so I need cucumberjs to produce a formatted report.
Any update on this? This has caused us enough issues to think about patching this module or looking at parallel-cucumber (which handles this case).
cucumberjs -> webdriverio
+1
I follow this description to save cucumberjs json format.
https://github.com/mrooding/gulp-protractor-cucumber-html-report#saving-cucumberjs-json-to-disk-when-using-protractor
It's work
if anyone is missing happy hour due to cucumber js reports, we are using cucumber-html-reports
support.registerHandler('AfterFeatures', () => {
///* creates report
var options = {
theme: 'bootstrap',
jsonFile: 'cucumberReports/report.json',
output: 'cucumberReports/report.html',
reportSuiteAsScenarios: true,
launchReport: true,
metadata: {
"App Version":"0.3.2",
"Test Environment": "POC",
//"Browser": "Chrome 54.0.2840.98",
//"Platform": "Windows 10",
//"Parallel": "Scenarios",
//"Executed": "Remote"
}
};
reporter.generate(options);
});
update your protractor.conf.cucumberOpts
format: 'json:cucumberReports/report.json',
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Most helpful comment
@cedriclombardot
There is a way to select a directory to json output from protractor from 1.5.0 though I haven't used it.
Currently, I added a hook so I can use pretty and json formatter together: