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

6

10

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?

Herrmann answered 22/7, 2022 at 7:17 Comment(4)
Where have you mentioned the tag regression? Is it in your step definition files?Catabolism
no, it's in my feature files.Herrmann
Can you add your feature file showing the tags to the question.Catabolism
Yes, I just added it in the description now.Herrmann
M
15

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,
  },
});
Mercurate answered 22/7, 2022 at 9:26 Comment(7)
I added these options in package.json, but now it's running all the features even though I added the regression tag in one feature. :(Herrmann
It worked for me, perhaps @badeball/cypress-cucumber-preprocessor": "^11.4.0 is different. I'll take a look.Mercurate
Can you share your cypress.config.js file? I don't think it's the issue with the version. I downgraded my version to 11.3.1 but still it's running all the features.Herrmann
Installed very latest "@badeball/cypress-cucumber-preprocessor": "^11.5.1" and the tag worked ok.Mercurate
"@badeball/cypress-cucumber-preprocessor": "11.4.0" is ok for me too.Mercurate
But how to have multiple tags ?Vickievicksburg
Use commas, as shown in the documentation.Mercurate
L
6

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
Legitimatize answered 22/7, 2022 at 7:34 Comment(4)
Will cypress-grep work with cucumber?Herrmann
I've not tried the two in combination, but I would expect so since cypress-tags was not specific to cucumber but did work with it.Legitimatize
I just tried this, but (as for now) it doesn't seem to work with cucumberFante
Yes it works with @badeball/cypress-cucumber.Seldom
L
0

please be aware that when you use tags with: and, or, inverted or not tags it uses a different syntax for @cypress/grep and cucumber tags (please look on the "Tag expressions" section).

According to the @suchanignorantthingtodo-ukr, First, enter the tags to cucumber tag and then to the @cypress/grep tag. Because, I want for example to use an "or" expression statement, and because those tags are eventually a single string, I just use the replace function to fit between the two approaches/plugins.

For example: For cucumber tags, I use the expression statement: '@night or @instalttion' And for @cypress/grep tags, I use the expression statement: '@night @instalttion'. So I just use the function:

on("file:preprocessor", webpackPreprocessor(webpackOptions));
cucumberConfig.env.grepTags = cucumberConfig.env.tags.replace('or', ' ')
const grepConfig = require('@cypress/grep/src/plugin')(cucumberConfig);

PS, I also recommend you use:

grepOmitFiltered: true

To avoiding to see that tests are skipped because of tags. But this is only my preference :)

Laboratory answered 20/3, 2024 at 14:51 Comment(0)
V
0

You can keep the cypress-cucumber-preprocessor:4.3.1 with cypress version 10+, the only thing is to change the new e2e folder back to integration as in cypress version 9. The cypress-tags command still works.

Volumed answered 9/7, 2024 at 21:8 Comment(0)
S
-1

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

Squarely answered 23/7, 2022 at 3:57 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Damaraland
S
-1
you can create config file like this 
const { defineConfig } = require("cypress");
const preprocessor = require("@badeball/cypress-cucumber-preprocessor");
const browserify = require("@badeball/cypress-cucumber-preprocessor/browserify");

 

 

async function setupNodeEvents(on, config) {
  
await preprocessor.addCucumberPreprocessorPlugin(on, config);
on("file:preprocessor", browserify.default(config));
return config;
}

 

 

module.exports = defineConfig({
  e2e: {
    setupNodeEvents,
    baseUrl:'',
    specPattern: "cypress/e2e/bdd-cucumber/features/*.feature",
    watchForFileChanges:false,
    chromeWebSecurity: false,
    experimentalModifyObstructiveThirdPartyCode: true,
    defaultCommandTimeout: 10000
},
});


and trigger cypress using npx cypress --config-file file --browser browser --env tags='tagname'
Subset answered 1/9, 2023 at 6:34 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.