From ae53b574228db97b296bd65c88ad760d797ac794 Mon Sep 17 00:00:00 2001 From: jimCresswell Date: Thu, 5 Mar 2015 10:52:52 +0000 Subject: [PATCH] Add json output Switch back to pretty print in the Protractor cucumberOpts and add a JSON output listener as per [https://github.com/cucumber/cucumber-js/issues/90#issuecomment-68544890] --- cucumber-report.json | 67 +++++++++++++++++++ .../json-reporter-listener.js | 16 +++++ protractor-conf.js | 2 +- 3 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 cucumber-report.json create mode 100644 features/support/output-listeners/json-reporter-listener.js diff --git a/cucumber-report.json b/cucumber-report.json new file mode 100644 index 0000000..f816dca --- /dev/null +++ b/cucumber-report.json @@ -0,0 +1,67 @@ +[ + { + "id": "Todo-list", + "name": "Todo list", + "description": "As a user of the todo list\r\nI want to be able to add and read todos\r\nSo that I can remember what I am supposed to do later", + "line": 2, + "keyword": "Feature", + "uri": "C:\\Users\\jimcr_000\\Documents\\GitHub\\cucumber-with-protractor-demo\\features\\todo.feature", + "elements": [ + { + "name": "Adding a todo", + "id": "Todo-list;adding-a-todo", + "line": 8, + "keyword": "Scenario", + "description": "", + "type": "scenario", + "tags": [ + { + "name": "@smoke", + "line": 7 + } + ], + "steps": [ + { + "keyword": "Before ", + "hidden": true, + "result": { + "duration": 883962, + "status": "passed" + }, + "match": {} + }, + { + "name": "I am on the app homepage.", + "line": 9, + "keyword": "Given ", + "result": { + "duration": 2737178804, + "status": "passed" + }, + "match": {} + }, + { + "name": "I add a todo called \"hello world\".", + "line": 10, + "keyword": "When ", + "result": { + "duration": 21925858, + "status": "passed" + }, + "match": {} + }, + { + "name": "I should see it added to the todo list.", + "line": 11, + "keyword": "Then ", + "result": { + "duration": 884422463, + "status": "passed" + }, + "match": {} + } + ] + } + ] + } +] \ No newline at end of file diff --git a/features/support/output-listeners/json-reporter-listener.js b/features/support/output-listeners/json-reporter-listener.js new file mode 100644 index 0000000..73fb2a6 --- /dev/null +++ b/features/support/output-listeners/json-reporter-listener.js @@ -0,0 +1,16 @@ +module.exports = function JsonOutputHook() { + var Cucumber = require('cucumber'); + var JsonFormatter = Cucumber.Listener.JsonFormatter(); + var fs = require('fs'); + + var filepath = 'cucumber-report.json'; + + JsonFormatter.log = function (json) { + fs.writeFile(filepath, json, function (err) { + if (err) throw err; + console.log('json file location: ' + filepath); + }); + }; + + this.registerListener(JsonFormatter); +}; \ No newline at end of file diff --git a/protractor-conf.js b/protractor-conf.js index d0657a0..665bebe 100644 --- a/protractor-conf.js +++ b/protractor-conf.js @@ -7,7 +7,7 @@ exports.config = { }, specs: ['features/*.feature'], cucumberOpts: { - format: 'json' + format: 'pretty' } };