Skip to content

Feature file synchronization⚓︎

The plugin allows you to keep your local feature files in sync with the step definitions in Xray.


Feature file upload⚓︎

cucumber plugin workflow cucumber plugin workflow

Synchronize step definitions in Xray based on your local feature files.

Uploading feature files is useful if the source of truth for test cases are local feature files in Cypress and Xray is only used for tracking execution results. You can enable the upload using the uploadFeatures setting and by making sure that feature file synchronization is enabled.

Tip

Don't forget to add tags to your backgrounds, scenarios and scenario outlines. Uploads of untagged feature files will always be skipped as a precautionary measure.

Example

In the following scenario, the existing example will be extended by an additional step.

1
2
3
4
5
6
7
8
Feature: Example page redirection

    @TestName:CYP-129
    Scenario: Redirect by clicking
        Given the example page
        When the link is clicked
        Then a redirect should occur
        And the test should fail
import { Given, Then, When } from "@badeball/cypress-cucumber-preprocessor";

Given("the example page", function () {
    cy.visit("https://example.org");
});

When("the link is clicked", function () {
    // Intercept the click, since it unfortunately redirects to a http:// location
    // and causes Cypress to abort the execution.
    cy.intercept("GET", "https://www.iana.org/domains/example", (request) => {
        request.reply("link was clicked");
    }).as("redirect");
    cy.get("a").click();
});

Then("a redirect should occur", function () {
    cy.wait("@redirect").then((request) => {
        expect(request.response.body).to.eq("link was clicked");
    });
});

Then("the test should fail", function () {
    expect(true).to.be.false;
});
import { addCucumberPreprocessorPlugin } from "@badeball/cypress-cucumber-preprocessor";
import createEsbuildPlugin from "@badeball/cypress-cucumber-preprocessor/esbuild";
import createBundler from "@bahmutov/cypress-esbuild-preprocessor";
import { configureXrayPlugin, syncFeatureFile } from "cypress-xray-plugin";
import fix from "cypress-on-fix";

// ...
async setupNodeEvents(on, config) {
    const fixedOn = fix(on);
    await addCucumberPreprocessorPlugin(fixedOn, config);
    await configureXrayPlugin(
        fixedOn,
        config,
        {
            jira: {
                projectKey: "CYP",
                url: "https://example.atlassian.net"
            }
            cucumber: {
                featureFileExtension: ".feature",
                uploadFeatures: true
            }
        }
    );
    fixedOn("file:preprocessor", async (file) => {
        await syncFeatureFile(file);
        const cucumberPlugin = createBundler({
            plugins: [createEsbuildPlugin(config)],
        });
        return cucumberPlugin(file);
    });
    return config;
}
// ...

Please note the the steps and the issue's summary changing due to the feature import.

Language support⚓︎

By default, Xray expects feature files to use English keywords. If you want to use different languages, make sure to add the corresponding # language: header to your feature files, as described here.

Example

1
2
3
4
5
6
7
8
# language: de
Funktionalität: Weiterleitung Beispielseite

    @TestName:CYP-129
    Szenario: Weiterleitung durch Klick
        Angenommen Beispielseite
        Wenn Klick auf Link
        Dann Weiterleitung findet statt

Feature file download⚓︎

Development

Synchronization of local feature files based on the step definitions as managed in Xray is planned as a future feature (i.e. download of Xray step definitions to local feature files and then running them).