Skip to content

Commit 4006d2d

Browse files
author
Marc Rooding
committed
Updated the README
1 parent 113d82a commit 4006d2d

File tree

1 file changed

+46
-16
lines changed

1 file changed

+46
-16
lines changed

README.md

Lines changed: 46 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
# gulp-protractor-cucumber-html-report
22

3-
> Generate html report from JSON file returned by cucumber js json formatter
4-
>
3+
> Generate html report from JSON file returned by CucumberJS json formatter
4+
5+
This is a stand-alone fork from [grunt-protractor-cucumber-html-report](https://github.com/robhil/grunt-protractor-cucumber-html-report)
56

67
## Getting Started
7-
This plugin requires Grunt `~3.9.0`
8+
This plugin requires Gulp `~3.9.0`
89

910
If you haven't used [Gulp](http://gulpjs.com/) before, be sure to check out the [Getting Started](https://github.com/gulpjs/gulp/blob/master/docs/getting-started.md) guide, as it explains how to create a Gulpfile as well as install and use Gulp plugins. Once you're familiar with that process, you may install this plugin with this command:
1011

@@ -21,30 +22,59 @@ var reporter = require('gulp-protractor-cucumber-html-report');
2122
## The "protractor-cucumber-html-report" task
2223

2324
### Overview
24-
In your project's Gulpfile, add a section named `protractor-cucumber-html-report` to the data object passed into `grunt.initConfig()`.
25+
In your project's Gulpfile, you can use the reporter in your pipeline as follows:
2526

2627
```js
27-
grunt.initConfig({
28-
protractor_cucumber_html_report: {
29-
options: {
30-
// Task-specific options go here.
31-
},
32-
your_target: {
33-
// Target-specific options go here.
34-
},
35-
},
36-
});
28+
gulp.src('./cucumber-test-results.json')
29+
.pipe(protractorReport({
30+
dest: 'reports/'
31+
}));
3732
```
3833

34+
### Saving CucumberJS json to disk when using Protractor
35+
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.
36+
37+
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.
38+
39+
```js
40+
module.exports = function JsonOutputHook() {
41+
var Cucumber = require('cucumber');
42+
var JsonFormatter = Cucumber.Listener.JsonFormatter();
43+
var fs = require('fs');
44+
var path = require('path');
45+
46+
JsonFormatter.log = function (json) {
47+
fs.writeFile(path.join(__dirname, './reports/cucumber-test-results.json'), json, function (err) {
48+
if (err) throw err;
49+
console.log('json file location: ' + path.join(__dirname, './reports/cucumber-test-results.json'));
50+
});
51+
};
52+
53+
this.registerListener(JsonFormatter);
54+
};
55+
```
56+
57+
Above snippet will hook into the CucumberJS JSON formatter and save the JSON to a file called 'cucumber-test-results.json' in the ./reports folder (relative from this file's location)/
58+
59+
### Setting up Protractor, CucumberJS and the JSON listener
60+
61+
In your protractor.conf.js add a reference to the hook listener (as shown above). In this example the file is found in 'support/'. Also make sure to set the output format to 'json'.
62+
63+
```js
64+
cucumberOpts: {
65+
require: ['steps/*.js', 'support/*.js'],
66+
format: 'json'
67+
},
68+
```
3969
### Options
4070

41-
#### dest
71+
#### options.dest
4272
Type: `String`
4373
Default value: `'.'`
4474

4575
The output directory for the HTML report relative from the Gulpfile
4676

47-
#### filename
77+
#### options.filename
4878
Type: `String`
4979
Default value: `'report.html'`
5080

0 commit comments

Comments
 (0)