You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#### Saving CucumberJS JSON to disk when using Protractor
51
-
If you're using Protractor in combination with CucumberJS there currently is [no way](https://github.com/cucumber/cucumber-js/issues/90) to save the CucumberJS JSON output to a file.
52
-
51
+
If you're using Protractor in combination with CucumberJS there currently is [no way](https://github.com/cucumber/cucumber-js/issues/90) to save the CucumberJS JSON output to a file.
52
+
53
53
It is however possible to add a listener to the CucumberJS JSON formatter and save it to a file manually. The following hook can be added to your project and included to your Protractor configuration.
54
54
55
55
I've added 2 different hooks which basically do the same but one of the 2 requires you to add an extra dependency to your package.json. You're free to choose which one you prefer.
@@ -111,20 +111,20 @@ var Cucumber = require('cucumber');
111
111
112
112
var JsonFormatter =Cucumber.Listener.JsonFormatter();
113
113
114
-
var reportFile =''../../reports/cucumber-test-results.json';
114
+
var reportsDir =path.join(__dirname, '../../reports');
115
+
var reportFile =path.join(reportsDir, 'cucumber-test-results.json');
115
116
116
117
module.exports=functionJsonOutputHook() {
117
118
JsonFormatter.log=function (json) {
118
-
var destination = path.join(__dirname, reportFile);
119
-
fs.open(destination, 'w+', function (err, fd) {
119
+
fs.open(reportFile, 'w+', function (err, fd) {
120
120
if (err) {
121
-
fs.mkdirsSync(destination);
122
-
fd = fs.openSync(destination, 'w+');
121
+
fs.mkdirsSync(reportsDir);
122
+
fd =fs.openSync(reportFile, 'w+');
123
123
}
124
124
125
125
fs.writeSync(fd, json);
126
126
127
-
console.log('json file location:' + destination);
127
+
console.log('json file location: '+reportFile);
128
128
});
129
129
};
130
130
@@ -174,22 +174,22 @@ This is all that's required to add the saved screenshots to the HTML report.
174
174
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality.
175
175
176
176
## Copyright
177
-
177
+
178
178
Copyright for portions of project [gulp-protractor-cucumber-html-report](https://github.com/mrooding/gulp-protractor-cucumber-html-report) are held by Robert Hilscher, 2015 as part of project [grunt-protractor-cucumber-html-report](https://github.com/robhil/grunt-protractor-cucumber-html-report). All other copyright for project [gulp-protractor-cucumber-html-report](https://github.com/mrooding/gulp-protractor-cucumber-html-report) are held by Marc Rooding, 2015.
179
179
180
180
## Release History
181
181
0.0.9:
182
182
- The readme now contains 2 different ways to use the JSON output hook. One using an external library and one without.
183
-
183
+
184
184
0.0.8:
185
185
- Fix for not ignoring the After screenshot step
186
-
186
+
187
187
0.0.7:
188
188
- Empty After steps as a result of the screenshot hook will not be added to the HTML report anymore
189
-
189
+
190
190
0.0.6:
191
191
- Support for saving screenshots of failed scenarios
192
-
192
+
193
193
0.0.5:
194
194
- More robust creation of the output directory [thanks smuldr!](https://github.com/smuldr)
195
195
- Fixed the HTML reporter when using multiple feature files
0 commit comments