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

Reporting - Output to file #90

Closed
peteclark82 opened this issue Oct 2, 2012 · 29 comments
Closed

Reporting - Output to file #90

peteclark82 opened this issue Oct 2, 2012 · 29 comments
Milestone

Comments

@peteclark82
Copy link

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.

@jbpros
Copy link
Member

jbpros commented Oct 2, 2012

There are actually two separate issues here:

  1. redirect formatter (not only JSON but pretty, progress, html, etc. as well) output to another file than STDOUT;
  2. allow for multiple formatters in a single run.

@jbpros
Copy link
Member

jbpros commented Oct 2, 2012

I created a separate issue regarding the multiple formatters.

@JRedgrave
Copy link

Julien is there any news on when we would be able to specify an HTML output file?

@neilD2
Copy link

neilD2 commented Jun 4, 2013

+1

1 similar comment
@mwinteringham
Copy link

+1

@letshaveyer
Copy link

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?

@letshaveyer
Copy link

Any update on this?

@aslakhellesoy
Copy link
Contributor

@letshaveyer this sounds like a useful feature to you. Why don't you send a pull request?

stejanse pushed a commit to stejanse/cucumber-js that referenced this issue May 27, 2014
nicolassenechal pushed a commit to nicolassenechal/cucumber-js that referenced this issue Jun 11, 2014
@brad8118
Copy link

brad8118 commented Aug 5, 2014

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
}
};

@samccone
Copy link
Member

samccone commented Aug 5, 2014

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

@brad8118
Copy link

brad8118 commented Aug 5, 2014

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" notifications@github.com 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
#90 (comment).

@samccone
Copy link
Member

samccone commented Aug 5, 2014

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.

@jlin412
Copy link

jlin412 commented Aug 5, 2014

@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
}
};

@jlin412
Copy link

jlin412 commented Aug 5, 2014

@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.

@brad8118
Copy link

brad8118 commented Aug 5, 2014

@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/cucumber-js@b337b18

@brad8118
Copy link

brad8118 commented Aug 5, 2014

@jlin412 when you cute and paste the json. What are you doing with it? Are you converting it into html?

@jlin412
Copy link

jlin412 commented Aug 5, 2014

@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.

stejanse pushed a commit to stejanse/cucumber-js that referenced this issue Aug 7, 2014
ioncache pushed a commit to ioncache/cucumber-js that referenced this issue Aug 20, 2014
stejanse pushed a commit to stejanse/cucumber-js that referenced this issue Aug 21, 2014
ioncache pushed a commit to ioncache/cucumber-js that referenced this issue Sep 16, 2014
@fraserc
Copy link

fraserc commented Oct 7, 2014

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.

@laurelnaiad
Copy link

+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...

@cedriclombardot
Copy link

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

@jlin412
Copy link

jlin412 commented Jan 2, 2015

@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);
};

@cedriclombardot
Copy link

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 notifications@github.com:

@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
#90 (comment).

jimCresswell added a commit to jimCresswell/cucumber-with-protractor-demo that referenced this issue Mar 5, 2015
Switch back to pretty print in the Protractor cucumberOpts and add a
JSON output listener as per
[cucumber/cucumber-js#90 (comment)]
@jbpros jbpros removed the ready label Jul 3, 2015
@cades
Copy link

cades commented Jul 16, 2015

+1

@fraserc
Copy link

fraserc commented Jul 23, 2015

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.

@auranine
Copy link

auranine commented Sep 3, 2015

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

@robcleghorn
Copy link

+1

@charlesh21
Copy link

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

  1. Add a listener to the CucumberJS JSON formatter and save it to a file
  2. protractor.conf.js add a reference to the hook listener

It's work

@noahehall
Copy link

noahehall commented Jul 28, 2017

if anyone is missing happy hour due to cucumber js reports, we are using cucumber-html-reports

  1. update your hooks.js
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',

@lock
Copy link

lock bot commented Oct 25, 2018

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.

@lock lock bot locked as resolved and limited conversation to collaborators Oct 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.