/cucumber-export

Prints and send your pretty test result directy to different destination (elk, http, kafka, slack etc...)

Primary LanguageJavaScriptMIT LicenseMIT

Cucumber-export

This cucumber formatter works well with cucumber versions from 6.x inclusive

Installation

npm install @restqa/cucumber-export

API

const { getFormatter } = require('@restqa/cucumber-export')

The getFormatter object expose a function receving your exports options. All The options are shared below.

cucumberExport.getFormatter([options])

Returns a cucumber formatter where the result will be pre-formatted and transferred to the selected destination.

Options

The Options are mandatory.

uuid <string> (optional)

Represent the unique identifier of current test suit exported.

Default: autogenerated from uuid : v4

name <string> (optional)

Represent the name of the current test suite (example: The backend api for the mobile application)

startTime <date> (optional)

Represent a unique key of the current test suite (example: 2018–01–30T12:34:56+00:00)

Default: current datetime

key <string> (optional)

Represent a unique key of the current test suite (example: backend-api)

env <string> (optional)

Represent a environment of the current test suite (example: uat)

outputs <array> (required)

You can configure different output, the available output reporters are :

File

Export the result to a JSON file

{
  type: 'file',
  enabled: true,
  config: {
    path: 'my-report.json' // File to save
  }
}
Http

Export the result to a http result

{
  type: 'http',
  enabled: true,
  config: {
    url: 'https://httpdump.io/rb6zi', // The http endpoint to send the result
    method: 'POST', // The http method to use
    headers: { // The request headers to use
      apikey: 'xxx-yyy-zzz'
    }
  }
}
Slack

Receive a notification on slack about you test report

{
  type: 'slack',
  enabled: true,
  config: {
    url: 'https://hooks.slack.com/service/xxx/yyy/zzz', // The slack webhook url
    onlyFailed: true, // Trigger the hook only for test failure  (default: false)
    showErrors: true,  // Show the error message within slack
    reportUrl: 'https://www.test.report/{uuid}' // The url to access to your detail test report if you have one
  }
}

Example:

slack notification

Elastic-Search

Export the result to an elastic search server (using rolling index)

{
  type: 'elastic-search',
  enabled: true,
  config: {
    url: 'http://my-elastic-search.local:9200', // The elastic search endpoint
    index: 'bdd-e2e'  // The elastic search index to use (default: restqa-e2e-result)
  }
}

Usage

Setup your formatter

Create a new file at the root of your project. (restqa-formatter.js)

# <root-dir>/restqa-formatter.js

const { getFormatter } = require('@restqa/cucumber-export')

let envConfig = {
  uuid: 'xxx-yyy-zzz',
  name: 'local',
  env: 'uat',
  outputs: [
    {
      type: 'http',
      enabled: true,
      config: {
        url: 'https://httpdump.io/lb8f7',
        method: 'POST',
        headers: {
          'x-apikey': 'xxx-yyy-zzz'
        }
      }
    },
    {
      type: 'elastic-search',
      enabled: true,
      config: {
        url: 'http://my-elastic-search.local:9200',
        index: 'bdd-e2e'
      }
    },
    {
      type: 'file',
      enabled: true,
      config: {
        path: 'my-report.json' // File to save
      }
    },
    {
      type: 'slack',
      enabled: true,
      config: {
        url: 'https://hooks.slack.com/service/xxx/yyy/zzz', // The slack webhook url
        onlyFailed: true, // Trigger the hook only for test failure  (default: false)
        showErrors: true,  // Show the error message within slack
        reportUrl: 'https://www.test.report/{uuid}' // The url to access to your detail test report if you have one
      }
    }
  ]
}

module.exports = getFormatter(envConfig)

Run cucumber-js

You can now run cucumber-js with the just created formatter

cucumber-js -f ./restqa-formatter.js:restqa.log

It's important to defined formatter export path to have access the logs, you can refer to the cucumber-js documentation (https://github.com/cucumber/cucumber-js/blob/master/docs/cli.md#formats)'

License

MIT License