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
}
}
This requires you to have registered this module in your plugin file, as shown below.
import { addCucumberPreprocessorPlugin } from "@klaveness/cypress-cucumber-preprocessor";
export default async (
on: Cypress.PluginEvents,
config: Cypress.PluginConfigOptions
): Promise<Cypress.PluginConfigOptions> => {
await addCucumberPreprocessorPlugin(on, config);
// Make sure to return the config object as it might have been modified by the plugin.
return config;
}
This also requires you to have downloaded and installed the cucumber-json-formatter yourself. Arch Linux users can install it from AUR.
The location of the executable is configurable through the json.formatter
property, but it will by default search for cucumber-json-formatter
in your PATH
.
The report is outputted to cucumber-report.json
in the project directory, but can be configured through the json.output
property.
Screenshots are automatically added to JSON reports, including that of failed tests (unless you have disabled screenshotOnRunFailure
).
Text, images and other data can be added to the output of the messages and JSON reports with attachments.
import { Given, attach } from "@klaveness/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 "@klaveness/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 "@klaveness/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 "@klaveness/cypress-cucumber-preprocessor";
Given("a step", function() {
attach("Zm9vYmFy", "base64:text/plain");
});