Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

run cypress using tags

I am using Cypress (version:10+) + Cucumber+ Typescript. I need to run the test using tags. Also, I tried cypress-tag but it's not working. Is there a way I can run the cypress test using tags without skipping the test?

like image 954
Suchit Narayan Avatar asked Sep 12 '25 15:09

Suchit Narayan


2 Answers

You can refer to this sample repository for your setup check it here: https://github.com/badeball/cypress-cucumber-preprocessor/tree/master/examples/browserify-ts

in your cypress.config.ts

import { defineConfig } from "cypress";
import { addCucumberPreprocessorPlugin } from "@badeball/cypress-cucumber-preprocessor";
import browserify from "@badeball/cypress-cucumber-preprocessor/browserify";

async function setupNodeEvents(
  on: Cypress.PluginEvents,
  config: Cypress.PluginConfigOptions
): Promise<Cypress.PluginConfigOptions> {
  await addCucumberPreprocessorPlugin(on, config);

  on(
    "file:preprocessor",
    browserify(config, {
      typescript: require.resolve("typescript"),
    })
  );

  // Make sure to return the config object as it might have been modified by the plugin.
  return config;
}

export default defineConfig({
  e2e: {
    specPattern: "**/*.feature",
    supportFile: false,
    setupNodeEvents,
  },
});

in your package.json should contain the following dependencies and important to set cypress-cucumber-preprocessor settings "filterSpecs: true" and "omitFiltered: true" to run successfully through tags

{
  "dependencies": {
    "@badeball/cypress-cucumber-preprocessor": "latest",
    "@cypress/browserify-preprocessor": "latest",
    "cypress": "latest",
    "typescript": "latest"
  },
  "cypress-cucumber-preprocessor": {
    "filterSpecs": true,
    "omitFiltered": true
  }
}

then you can run your feature files like this:

cypress run --env tags=@foo
like image 172
Ry-ry Avatar answered Sep 16 '25 11:09

Ry-ry


Best solution to it is the Cucumber Cypress preprocessor. I was able run my test using tags without any issue. The problem I faced in Cypress version 10 was the Itegration folder in the Cypress folder structure was renamed to e2e folder. And in Cucumber-Cypress-preprocessor will always look for files in integration folder (which was there in Cypress version less than 10) for searching tags.

like image 31
Suchit Narayan Avatar answered Sep 16 '25 09:09

Suchit Narayan