0

I'm using "protractor-cucumber-framework" to use Cucumber along with Protractor for automation(Using CHAI as Assertion Library).

I'm using resultJsonOutputFile: './report.json' to generate a JSON log report. I can not see step information in the log file rather it just shows passed attribute for each block. Sample feature file and and JSON report generated attached below.

sample json file

sample feature file

I want to include the text after "Then" in the feature file for ex. Is that possible?

halfer
  • 19,824
  • 17
  • 99
  • 186

1 Answers1

0

The resultJsonOutputFile will generate json file attributed to protractor and will contain basic specs information. Since you are using Cucumber as your testing framework with protractor you would have to generate Cucumber-Report.json which cucumber generates.It will have all your step definition details! In order to achieve this you could add below code in your hooks.js file:

var Cucumber = require('cucumber'); //npm install -g cucumber
var jsonReporter = function () {
"use strict";
var outputDir = './Reports/';
var JsonFormatter = Cucumber.Listener.JsonFormatter();
JsonFormatter.log = function (string) {
    if (!fs.existsSync(outputDir)) {
        fs.mkdirSync(outputDir);
    }

var targetJson = outputDir + 'cucumber_report.json';
    fs.writeFile(targetJson, string, function (err) {
        if (err) {
            console.log('Failed to save cucumber test results to json file.');
            console.log(err);
        } 
    });
};
this.registerListener(JsonFormatter);

module.exports = jsonReporter;

This would create a Reports folder and in that you would see cucumber_report.json file

Ram Pasala
  • 4,931
  • 3
  • 16
  • 26
  • Thanks @igniteram1 for the answer. As I'm new to cucumber I'm not able to wired up this hooks.js to my stepdef file. I've feature file, hooks.js,stepdefinition file in a folder. Sibiling to this folder I've conf.js. Can you please tell me where should I require this hooks file which will create json file. – naresh surya Aug 12 '16 at 11:50
  • you have to require them in your `conf.js` in `cucumberOpts` along with your step definitions! – Ram Pasala Aug 12 '16 at 12:14
  • Yeah I did, and I'm able to generate json file as expected. Thank you – naresh surya Aug 12 '16 at 18:04
  • Glad It worked! Please accept the answer if it solved your issue as it would help others having similar problem :) – Ram Pasala Aug 12 '16 at 18:19
  • @igniteram, Can we have this hooks.js code in conf.js either in anyof the block like onPrepare/Oncomplete etc. instead of having in separate file and requiring in require block? – naresh surya Sep 08 '16 at 11:31