CucumberJS JSON Reporter
wdio-cucumberjs-json-reporter is a 3rd party package, for more information please see GitHub | npm
A WDIO reporter that creates CucumberJS JSON files for WebdriverIO v8 and up.
What does it do
This reporter will generate a Cucumber JSON file for each feature that is being tested. The JSON file can be used with whatever report you want to use like for example multiple-cucumber-html-reporter.
It will also add metadata about the running instance to the feature file and last but not least, it will give you the opportunity to add attachments to the JSON output.
Installation
The easiest way is to keep wdio-cucumberjs-json-reporter
as a devDependency in your package.json
.
{
"devDependencies": {
"wdio-cucumberjs-json-reporter": "^5.0.0"
}
}
You can simple do it by:
npm install wdio-cucumberjs-json-reporter --save-dev
so it will automatically be added to your package.json
Instructions on how to install WebdriverIO
can be found here.
Configuration
Configure the output directory and the language in your wdio.conf.js file:
export const config = {
// ...
reporters: [
// Like this with the default options, see the options below
'cucumberjs-json',
// OR like this if you want to set the folder and the language
[ 'cucumberjs-json', {
jsonFolder: '.tmp/new/',
language: 'en',
},
],
],
// ...
}
DON'T USE BOTH WAYS OF ADDING THE REPORTER, THIS IS JUST AN EXAMPLE!
Options
jsonFolder
- Type:
String
- Mandatory: No
- Default:
.tmp/json/
The directory where the JSON files, generated by this report, will be stored, relative from where the script is started.
N.B.: If you use a npm script from the command line, like for example npm run test
the jsonFolder
will be relative from the path
where the script is executed. Executing it from the root of your project will also create the jsonFolder
in the root of you project.
language
- Type:
String
- Mandatory: No
- Default:
en
The language in which the Gherkin scenarios are written (defaults to English). The list of language codes and its keywords can be found here.
disableHooks
- Type:
boolean
- Mandatory: No
- Default:
false
Hook details will not be part of generation if this property sets to true
.
reportFilePerRetry
- Type:
boolean
- Mandatory: No
- Default:
true
When a spec is retried the report will be appended to the existing report file from the previous tries if this property is set to false
.
Example:
['cucumberjs-json', { jsonFolder: '.tmp/new/', language: 'en', disableHooks:true}]
Metadata
Note:
This is currently not supported if you are using WebdriverIO V6, WebdriverIO V5 still supports this and WebdriverIO V7 supports it again
As said, this report can automatically store the metadata of the current machine / device the feature has been executed on.
To customize this you can add it by adding the following object to your capabilities
// Example wdio.conf.js
export const config = {
//..
capabilities: [
{
browserName: 'chrome',
// Add this
'cjson:metadata': {
// For a browser
browser: {
name: 'chrome',
version: '58',
},
// for an app
app: {
name: 'name.of.app.ipa',
version: '1.2.3',
},
device: 'MacBook Pro 15',
platform: {
name: 'OSX',
version: '10.12.6'
}
},
},
],
};
The metadata object needs to have the
cjson
prefix, otherwise it will not work!
Metadata values
metadata.app.name
- Type:
string
e.g.: The name of the app.
metadata.app.version
- Type:
string
e.g.: The version of the app.
metadata.browser.name
- Type:
string
- Possible values:
internet explorer | edge | chrome | firefox | safari