Skip to content

Latest commit

 

History

History
115 lines (85 loc) · 3.34 KB

json-report.md

File metadata and controls

115 lines (85 loc) · 3.34 KB

← Back to documentation

JSON reports

JSON reports can be enabled using the json.enabled property. The preprocessor uses cosmiconfig, which means you can place configuration options in EG. .cypress-cucumber-preprocessorrc.json or package.json. An example configuration is shown below.

{
  "json": {
    "enabled": true
  }
}

The report is outputted to cucumber-report.json in the project directory, but can be configured through the json.output property.

Screenshots

Screenshots are automatically added to JSON reports, including that of failed tests (unless you have disabled screenshotOnRunFailure).

Attachments (browser environment)

Text, images and other data can be added to the output of the messages and JSON reports with attachments, using the browser API explained below.

import { Given, attach } from "@badeball/cypress-cucumber-preprocessor";

Given("a step", function() {
  attach("foobar");
});

By default, text is saved with a MIME type of text/plain. You can also specify a different MIME type.

import { Given, attach } from "@badeball/cypress-cucumber-preprocessor";

Given("a step", function() {
  attach('{ "name": "foobar" }', "application/json");
});

Images and other binary data can be attached using a ArrayBuffer. The data will be base64 encoded in the output.

import { Given, attach } from "@badeball/cypress-cucumber-preprocessor";

Given("a step", function() {
  attach(new TextEncoder().encode("foobar").buffer, "text/plain");
});

If you've already got a base64-encoded string, you can prefix your mime type with base64: to indicate this.

import { Given, attach } from "@badeball/cypress-cucumber-preprocessor";

Given("a step", function() {
  attach("Zm9vYmFy", "base64:text/plain");
});

Attachments (node environment)

Similar to the browser API explained above, attachments can also be added using a Node API. This is less typical and only required in specific scenarios. This API is available through the onAfterStep option in addCucumberPreprocessorPlugin, like shown below. The Node API mimicks the options found in the browser API.

await addCucumberPreprocessorPlugin(on, config, {
  onAfterStep({ wasLastStep, attach }) {
    attach("foobar");
  }
});

By default, text is saved with a MIME type of text/plain. You can also specify a different MIME type.

await addCucumberPreprocessorPlugin(on, config, {
  onAfterStep({ wasLastStep, attach }) {
    attach('{ "name": "foobar" }', "application/json");
  }
});

Images and other binary data can be attached using a Buffer. The data will be base64 encoded in the output.

await addCucumberPreprocessorPlugin(on, config, {
  onAfterStep({ wasLastStep, attach }) {
    attach(Buffer.from("foobar"), "text/plain");
  }
});

If you've already got a base64-encoded string, you can prefix your mime type with base64: to indicate this.

await addCucumberPreprocessorPlugin(on, config, {
  onAfterStep({ wasLastStep, attach }) {
    attach("Zm9vYmFy", "base64:text/plain");
  }
});

A wasLastStep option is available if you need to attach something at the end of the test.

await addCucumberPreprocessorPlugin(on, config, {
  onAfterStep({ wasLastStep, attach }) {
    if (wasLastStep) {
      attach("foobar");
    }
  }
});