UNPKG

10.2 kBMarkdownView Raw
1# cucumber-html-reporter
2
3***Generate Cucumber HTML reports with pie charts***
4
5[![Build Status](https://travis-ci.org/gkushang/cucumber-html-reporter.svg?branch=develop)](https://travis-ci.org/gkushang/cucumber-html-reporter) [![npm](https://img.shields.io/npm/v/cucumber-html-reporter.svg)](https://www.npmjs.com/package/cucumber-html-reporter) [![Dependency Status](https://david-dm.org/gkushang/cucumber-html-reporter.svg)](https://david-dm.org/gkushang/cucumber-html-reporter) [![Code Climate](https://codeclimate.com/github/gkushang/cucumber-html-reporter/badges/gpa.svg)](https://codeclimate.com/github/gkushang/cucumber-html-reporter) [![License](https://img.shields.io/npm/l/cucumber-html-reporter.svg)](LICENSE) [![contributors](https://img.shields.io/github/contributors/gkushang/cucumber-html-reporter.svg)](https://github.com/gkushang/cucumber-html-reporter/graphs/contributors)
6
7
8> Available HTML themes: `['bootstrap', 'hierarchy', 'foundation', 'simple']`
9
10## Preview of HTML Reports
11
12Provide Cucumber JSON report file created from your framework and this module will create pretty HTML reports. Choose your best suitable HTML theme and dashboard on your CI with available HTML reporter plugins.
13
141. [Bootstrap Theme Reports with Pie Chart][4]
152. [Hierarchical Feature Structure Theme Reports With Pie Chart][3]
163. [Foundation Theme Reports][5]
174. [Simple Theme Reports][6]
18
19
20## Snapshot of Bootstrap Report
21![Alt text](/samples/html_report_snapshots/cucumber_report_bootstrap_snapshot.png "Snapshot - Bootstrap Report")
22
23###### More snapshots are availble [here][9]
24
25## Install
26
27``` bash
28npm install cucumber-html-reporter --save-dev
29```
30
31***Notes:***
32
33* Latest version supports Cucumber 3
34* Install `cucumber-html-reporter@2.0.3` for cucumber version `< Cucumber@3`
35* Install `cucumber-html-reporter@0.5.0` for cucumber version `< Cucumber@2`
36* Install `cucumber-html-reporter@0.4.0` for node version <0.12
37
38
39## Usage
40
41Let's get you started:
42
431. Install the package through npm
442. Create an index.js and specify the options. Example of `bootstrap` theme:
45
46```js
47
48var reporter = require('cucumber-html-reporter');
49
50var options = {
51 theme: 'bootstrap',
52 jsonFile: 'test/report/cucumber_report.json',
53 output: 'test/report/cucumber_report.html',
54 reportSuiteAsScenarios: true,
55 launchReport: true,
56 metadata: {
57 "App Version":"0.3.2",
58 "Test Environment": "STAGING",
59 "Browser": "Chrome 54.0.2840.98",
60 "Platform": "Windows 10",
61 "Parallel": "Scenarios",
62 "Executed": "Remote"
63 }
64 };
65
66 reporter.generate(options);
67
68
69 //more info on `metadata` is available in `options` section below.
70
71 //to generate consodilated report from multi-cucumber JSON files, please use `jsonDir` option instead of `jsonFile`. More info is available in `options` section below.
72
73```
74> Please look at the [Options](https://github.com/gkushang/cucumber-html-reporter#options) section below for more options
75
763. Run the above code in a node.js script after Cucumber execution:
77```bash
78node index.js
79```
80
81#### For CucumberJS
82
83This module converts Cucumber's JSON format to HTML reports.
84> The code has to be separated from CucumberJS execution (after it).
85
86In order to generate JSON formats, run the Cucumber to create the JSON format and pass the file name to the formatter as shown below,
87
88```bash
89$ cucumberjs test/features/ -f json:test/report/cucumber_report.json
90```
91
92Multiple formatter are also supported,
93
94```bash
95$ cucumberjs test/features/ -f summary -f json:test/report/cucumber_report.json
96```
97
98> Are you using cucumber with other frameworks or running [cucumber-parallel][7]? Pass relative path of JSON file to the `options` as shown [here][8]
99
100
101## Options
102
103#### `theme`
104Available: `['bootstrap', 'hierarchy', 'foundation', 'simple']`
105Type: `String`
106
107Select the Theme for HTML report.
108
109N.B: Hierarchy theme is best suitable if your features are organized under features-folder hierarchy. Each folder will be rendered as a HTML Tab. It supports up to 3-level of nested folder hierarchy structure.
110
111
112#### `jsonFile`
113Type: `String`
114
115Provide path of the Cucumber JSON format file
116
117#### `jsonDir`
118Type: `String`
119
120If you have more than one cucumber JSON files, provide the path of JSON directory. This module will create consolidated report of all Cucumber JSON files.
121
122e.g. `jsonDir: 'test/reports'` //where _reports_ directory contains valid `*.json` files
123
124
125N.B.: `jsonFile` takes precedence over `jsonDir`. We recommend to use either `jsonFile` or `jsonDir` option.
126
127
128#### `output`
129Type: `String`
130
131Provide HTML output file path and name
132
133
134#### `reportSuiteAsScenarios`
135Type: `Boolean`
136Supported in the Bootstrap theme.
137
138`true`: Reports total number of passed/failed scenarios as HEADER.
139
140`false`: Reports total number of passed/failed features as HEADER.
141
142#### `launchReport`
143Type: `Boolean`
144
145Automatically launch HTML report at the end of test suite
146
147`true`: Launch HTML report in the default browser
148
149`false`: Do not launch HTML report at the end of test suite
150
151#### `ignoreBadJsonFile`
152Type: `Boolean`
153
154Report any bad json files found during merging json files from directory option.
155
156`true`: ignore any bad json files found and continue with remaining files to merge.
157
158`false`: Default option. Fail report generation if any bad files found during merge.
159
160#### `name`
161Type: `String` (optional)
162
163Custom project name. If not passed, module reads the name from projects package.json which is preferable.
164
165#### `brandTitle`
166Type: `String` (optional)
167
168Brand Title is the brand of your report, e.g. Smoke Tests Report, Acceptance Test Report etc as per your need. If not passed, it will be displayed as "Cucumberjs Report"
169
170#### `columnLayout`
171Available: `[1, 2]`
172Type: `Number`
173Default: 2
174
175Select the Column Layout. One column or Two columns
176
1771 = One Column layout (col-xx-12)
1782 = Two Columns Layout (col-xx-6)
179
180#### `storeScreenshots`
181Type: `Boolean`
182Default: `undefined`
183
184`true`: Stores the screenShots to the default directory. It creates a directory 'screenshot' if does not exists.
185
186`false` or `undefined` : Does not store screenShots but attaches screenShots as a step-inline images to HTML report
187
188#### `screenshotsDirectory`
189Type: `String` (optional)
190Default: `options.output/../screenshots`
191
192Applicable if `storeScreenshots=true`. Relative path for directory where screenshots should be saved. E.g. the below options should store the screenshots to the `<parentDirectory>/screenshots/` where as the report would be at `<parentDirectory>/report/cucumber_report.html`
193
194```js
195{
196 ...
197 ...
198 output: '/report/cucumber_report.html',
199 screenshotsDirectory: 'screenshots/',
200 storeScreenshots: true
201}
202```
203
204#### `noInlineScreenshots`
205Type: `Boolean`
206Default: `undefined`
207
208`true`: Applicable if `storeScreenshots=true`. Avoids inlining screenshots, uses relative path to screenshots instead (i.e. enables lazy loading of images).
209
210`false` or `undefined`: Keeps screenshots inlined.
211
212#### `metadata`
213Type: `JSON` (optional)
214Default: `undefined`
215
216Print more data to your report, such as _browser info, platform, app info, environments_ etc. Data can be passed as JSON `key-value` pair. Reporter will parse the JSON and will show the _Key-Value_ under `Metadata` section on HTML report. Checkout the below preview HTML Report with Metadata.
217
218Pass the _Key-Value_ pair as per your need, as shown in below example,
219
220```js
221
222 metadata: {
223 "App Version":"0.3.2",
224 "Test Environment": "STAGING",
225 "Browser": "Chrome 54.0.2840.98",
226 "Platform": "Windows 10",
227 "Parallel": "Scenarios",
228 "Executed": "Remote"
229 }
230
231```
232
233* [HTML Report Preview with Metadata][4]
234* [Report Snapshot with Metadata][11]
235
236
237## Tips
238
239#### Attach Screenshots to HTML report
240
241Capture and Attach screenshots to the Cucumber Scenario and HTML report will render the screenshot image
242
243**for Cucumber V1**
244```javascript
245
246 driver.takeScreenshot().then(function (buffer) {
247 return scenario.attach(new Buffer(buffer, 'base64'), 'image/png');
248 };
249
250```
251
252**for Cucumber V2 and V3**
253```javascript
254
255 var world = this;
256
257 driver.takeScreenshot().then(function (buffer) {
258 return world.attach(buffer, 'image/png');
259 };
260
261```
262
263#### Attach Plain Text to HTML report
264
265Attach plain-texts/data to HTML report to help debug/review the results
266
267```javascript
268
269 scenario.attach('test data goes here');
270
271```
272
273#### Attach pretty JSON to HTML report
274
275Attach JSON to HTML report
276
277```javascript
278
279 scenario.attach(JSON.stringify(myJsonObject, undefined, 4));
280
281```
282
283## Changelog
284
285[changelog][10]
286
287
288## Credits
289
290Credit to the developers of [grunt-cucumberjs][1] for developing pretty HTML reporting. HTML reporting is extracted from the grunt task. Thanks to all the contributors for making HTML Reporting available to the wider audiences of [cucumber-js][2] community.
291
292[1]: https://www.npmjs.com/package/grunt-cucumberjs "grunt-cucummberjs"
293[2]: https://github.com/cucumber/cucumber-js "CucumberJs"
294[3]: http://htmlpreview.github.io/?https://github.com/gkushang/cucumber-html-reporter/blob/develop/samples/html_reports/cucumber_report_hierarchy.html "Hierarchy Theme Reports"
295[4]: http://htmlpreview.github.io/?https://github.com/gkushang/cucumber-html-reporter/blob/develop/samples/html_reports/cucumber_report_bootstrap.html "Bootstrap Theme Reports"
296[5]: http://htmlpreview.github.io/?https://github.com/gkushang/cucumber-html-reporter/blob/develop/samples/html_reports/cucumber_report_foundation.html "Foundation Theme Reports"
297[6]: http://htmlpreview.github.io/?https://github.com/gkushang/cucumber-html-reporter/blob/develop/samples/html_reports/cucumber_report_simple.html "Simple Theme Reports"
298[7]: https://www.npmjs.com/package/cucumber-parallel "cucumber-parallel"
299[8]: https://github.com/gkushang/cucumber-html-reporter/blob/develop/test/features/step_definitions/hooks.js#L13-L44
300[9]: https://github.com/gkushang/cucumber-html-reporter/blob/develop/samples/snapshots.md
301[10]: https://github.com/gkushang/cucumber-html-reporter/blob/develop/CHANGELOG.md
302[11]: https://github.com/gkushang/cucumber-html-reporter/blob/develop/samples/snapshots.md#with-metadata
303[twitter]: https://twitter.com/g_kushang
304
305
306