Skip to content

Commit

Permalink
Add json output
Browse files Browse the repository at this point in the history
Switch back to pretty print in the Protractor cucumberOpts and add a
JSON output listener as per
[cucumber/cucumber-js#90 (comment)]
  • Loading branch information
jimCresswell committed Mar 5, 2015
1 parent 384da10 commit ae53b57
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 1 deletion.
67 changes: 67 additions & 0 deletions cucumber-report.json
Original file line number Diff line number Diff line change
@@ -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": {}
}
]
}
]
}
]
16 changes: 16 additions & 0 deletions features/support/output-listeners/json-reporter-listener.js
Original file line number Diff line number Diff line change
@@ -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);
};
2 changes: 1 addition & 1 deletion protractor-conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ exports.config = {
},
specs: ['features/*.feature'],
cucumberOpts: {
format: 'json'
format: 'pretty'
}
};

0 comments on commit ae53b57

Please sign in to comment.