Cucumber tags are not working after Cypress and cucumber-preprocessor upgrade

Viewed 585

I upgraded Cypress from 9.5.2 to 10.3.0 and previously I was using cypress-cucumber-preprocessor:4.3.1 now I upgrade it to @badeball/cypress-cucumber-preprocessor:^11.4.0.

Before the upgrade, I was using cypress-tags for running the test using command

npx cypress-tags run --env TAGS="@regression" --browser chrome

but after the upgrade it's throwing me below error.

npm ERR! could not determine executable to run

Please find the sample feature below

Feature: Login Features

    @regression
    Scenario: Test sample login
        Given I login to the website as "testUser"

Can someone help me to get an alternate option for running tests based on the tags with the latest Cypress and cucumber?

3 Answers

TLDR

Just remove cypress-tags altogether, but a good enhancement is to add filterSpecs and omitFiltered options.


From this page Transfer of ownership

The cypress-tags has been removed and made redundant. Specs containing no matching scenarios are automatically filtered, provided that filterSpecs is set to true.

So, if I run

npx cypress run --env tags="@regression"

I get results like

      Spec                                              Tests  Passing  Failing  Pending  Skipped  
  ┌────────────────────────────────────────────────────────────────────────────────────────────────┐
  │ √  duckduckgo.feature                         0ms        -        -        -        -        - │
  ├────────────────────────────────────────────────────────────────────────────────────────────────┤
  │ √  duckduckgo2.feature                      00:04        1        1        -        -        - │
  └────────────────────────────────────────────────────────────────────────────────────────────────┘
    √  All specs passed!                        00:04        1        1        -        -        -  

which has done the job (duckduckgo2.feature has the regression tag).

But it's better with these two config options

package.json

{
  ...
  "devDependencies": {
    "@badeball/cypress-cucumber-preprocessor": "^11.3.1",
    "cypress": "^10.3.0",
  },
  "cypress-cucumber-preprocessor": {
    "filterSpecs": true,
    "omitFiltered": true
  }
}

I now get

     Spec                                              Tests  Passing  Failing  Pending  Skipped  
  ┌────────────────────────────────────────────────────────────────────────────────────────────────┐
  │ √  duckduckgo2.feature                      00:04        1        1        -        -        - │
  └────────────────────────────────────────────────────────────────────────────────────────────────┘
    √  All specs passed!                        00:04        1        1        -        -        -  

cypress.config.js

const { defineConfig } = require("cypress");
const createBundler = require("@bahmutov/cypress-esbuild-preprocessor");
const preprocessor = require("@badeball/cypress-cucumber-preprocessor");
const createEsbuildPlugin = require("@badeball/cypress-cucumber-preprocessor/esbuild");

async function setupNodeEvents(on, config) {
  await preprocessor.addCucumberPreprocessorPlugin(on, config);

  on(
    "file:preprocessor",
    createBundler({
      plugins: [createEsbuildPlugin.default(config)],
    })
  );

  return config;
}

module.exports = defineConfig({
  e2e: {
    specPattern: "**/*.feature",
    supportFile: false,
    setupNodeEvents,
  },
});

An alternative that has been updated for Cypress 10 is cypress-grep.

One of it's features is the run tests by tag,

Start grepping by title and tags:

# run only the tests with "auth user" in the title
$ npx cypress run --env grep="auth user"

# run tests with "hello" or "auth user" in their titles
# by separating them with ";" character
$ npx cypress run --env grep="hello; auth user"

# run tests tagged @fast
$ npx cypress run --env grepTags=@fast

# run only the tests tagged "smoke"
# that have "login" in their titles
$ npx cypress run --env grep=login,grepTags=smoke

# only run the specs that have any tests with "user" in their titles
$ npx cypress run --env grep=user,grepFilterSpecs=true

# only run the specs that have any tests tagged "@smoke"
$ npx cypress run --env grepTags=@smoke,grepFilterSpecs=true

# run only tests that do not have any tags
# and are not inside suites that have any tags
$ npx cypress run --env grepUntagged=true

From terminal try below command, npx cypress run --spec '**/*.feature' -e TAGS='@NonCrud' --browser chrome --headless

Related