5.2.2 • Public • Published


Agent to integrate CucumberJS with ReportPortal.

This agent works well with cucumber versions from 7.x to 9.x. Documentation for legacy cucumber versions from 4.x to 6.x can be found here

Install agent to your project dir

npm install --save-dev @reportportal/agent-js-cucumber
  1. Make sure that you required glue code correctly. It is important to make Cucumber see support code. For example: Let's say you have project structure like this below

      L features
          L step_definitions
              L steps.js
              L support
                  L hooks.js
                  L world.js
      L package.json


    Protractor and Cucumber have their own timeouts . When protractor start main process that launches cucumber it would have different timeouts if they are not the same they would wait for scripts different time. If cucumber's timeout less than protractor's it would through wrong exception. For example if page that has been loaded and hasn't got angular, the next error would be thrown : Error: function timed out after 10000 milliseconds . . . . Instead of protractor's : Error: Error while running testForAngular: asynchronous script timeout: result was not received in 4 seconds . . . . So it must be handled manually by setting cucumber's timeout greater than protractor's is at the hooks.js. For example if you set up protractor's timeout 9000 miliseconds , so cucumber must be at least 1 second greater = 10000 miliseconds. Example :

    var { setDefaultTimeout } = require('@cucumber/cucumber');
  2. Create Report Portal configuration file For example ./rpConfig.json

      "apiKey": "reportportalApiKey",
      "endpoint": "https://your.reportportal.server/api/v1",
      "launch": "Your launch name",
      "project": "Your reportportal project name",
      "description": "Awesome launch description.",
      "attributes": [
          "key": "launchAttributeKey",
          "value": "launchAttributeValue"
      "takeScreenshot": "onFailure"

The full list of available options presented below.

Option Necessity Default Description
apiKey Required User's reportportal token from which you want to send requests. It can be found on the profile page of this user.
endpoint Required URL of your server. For example 'https://server:8080/api/v1'.
launch Required Name of launch at creation.
project Required The name of the project in which the launches will be created.
attributes Optional [] Launch attributes.
description Optional '' Launch description.
rerun Optional false Enable rerun
rerunOf Optional Not set UUID of launch you want to rerun. If not specified, reportportal will update the latest launch with the same name
mode Optional 'DEFAULT' Results will be submitted to Launches page
'DEBUG' - Results will be submitted to Debug page.
skippedIssue Optional true reportportal provides feature to mark skipped tests as not 'To Investigate'.
Option could be equal boolean values:
true - skipped tests considered as issues and will be marked as 'To Investigate' on reportportal.
false - skipped tests will not be marked as 'To Investigate' on application.
debug Optional false This flag allows seeing the logs of the client-javascript. Useful for debugging.
takeScreenshot Optional Not set Possible values: onFailure. If this option is defined then framework will take screenshot with protractor or webdriver API if step has failed.
scenarioBasedStatistics Optional false While true, the Gherkin Scenarios considered as entity with statistics. In this case Cucumber steps will be reported to the log level as nested steps.
restClientConfig Optional Not set The object with agent property for configure http(s) client, may contain other client options eg. timeout.
Visit client-javascript for more details.
token Deprecated Not set Use apiKey instead.
  1. Create Report Portal formatter in a new js file, for example reportPortalFormatter.js:

    const { createRPFormatterClass } = require('@reportportal/agent-js-cucumber');
    const config = require('./rpConfig.json');
    module.exports = createRPFormatterClass(config);
  2. Import RPWorld (provides API for logging and data attaching) into /features/step_definitions/support/world.js

    let { setWorldConstructor } = require('@cucumber/cucumber');
    let { RPWorld } = require('@reportportal/agent-js-cucumber');

    If you have other world constructors it must be used with the RPWorld as shown below

    class CustomWorld extends RPWorld {
      constructor(...args) {
         * any driver container must be named 'browser', because reporter could be used with cucumber
         * and protractor. And protractor has global object browser which contains all web-driver methods
        global.browser = new seleniumWebdriver.Builder().forBrowser('chrome').build();

    It will allow you send logs and screenshots to RP directly from step definitions. All this logs would be attached to test data and could be viewed at the Report Portal.
    Also you will be able to specify additional info for test items (e.g. description, attributes, testCaseId, status). See API section for more information.

  3. Run cucumber-js

    cucumber-js -f ./reportPortalFormatter.js

    More info in the examples repository.

Step reporting configuration

By default, this agent reports the following structure:

  • feature - SUITE
  • scenario - TEST
  • step - STEP

You may change this behavior to report steps to the log level by enabling scenario-based reporting:

  • feature - TEST
  • scenario - STEP
  • step - log item (nested step)

To report your steps as logs without creating statistics for every step, you need to pass an additional parameter to the agent config: "scenarioBasedStatistics": true

  "scenarioBasedStatistics": true



Attachments are being reported as logs. You can either just attach a file using cucumber's this.attach or specify log level and message:

    message: `Attachment with ${type}`,
    level: 'INFO',
    data: data.toString('base64'),

To send attachment to the launch just specify entity: 'launch' property.

Also this.screenshot and this.launchScreenshot methods can be used to take screenshots.

Then(/^I should see my new task in the list$/, function(callback) {
  this.screenshot('This screenshot')
    .then(() => callback())
    .catch((err) => callback(err));
  this.launchScreenshot('This is screenshot for launch')
    .then(() => callback())
    .catch((err) => callback(err));

screenshot/launchScreenshot function return promise fulfilled after screenshot is taken and image added to attachments. Handler will parse attachments and send corresponding log to the step item.


To report logs to the items you can use the next methods:

Then(/^I should see my new task in the list$/, function() {
  this.info('This is Info Level log');
  this.debug('This is Debug Level log');
  this.error('This is Error Level log');
  this.warn('This is Warn Level log');
  this.trace('This is Trace Level log');
  this.fatal('This is Fatal Level log');

To report logs to the launch you can use the next methods:

Then(/^I should see my new task in the list$/, function() {
  this.launchInfo('This is Info Level log');
  this.launchDebug('This is Debug Level log');
  this.launchError('This is Error Level log');
  this.launchWarn('This is Warn Level log');
  this.launchTrace('This is Trace Level log');
  this.launchFatal('This is Fatal Level log');


Attributes for features and scenarios are parsed from @tags as @key:value pair.

To add attributes to the items you can use the next method:

Then(/^I should see my new task in the list$/, function() {
  this.addAttributes([{ key: 'agent', value: 'cucumber' }]);

The attributes will be concatenated.


Description for features and scenarios are parsed from their definition.

To add description to the items you can use the following method:

Then(/^I should see my new task in the list$/, function() {
  this.addDescription('Test item description.');

The description will be concatenated.


To set test case id to the items you can use the following method:

Then(/^I should see my new task in the list$/, function() {


The user can set the status of the item/launch directly depending on some conditions or behavior. It will take precedence over the actual completed status.

To set status to the item you can use the next methods:

Then(/^I should see my new task in the list$/, function() {

To set status to the item you can use the next methods:

Then(/^I should see my new task in the list$/, function() {

Copyright Notice

Licensed under the Apache 2.0 license (see the LICENSE.txt file).


DownloadsWeekly Downloads






Unpacked Size

141 kB

Total Files


Last publish


  • reportportal-admin
  • fizik2009
  • amsterget
  • davert