cucumbercypressfeature-filecypress-cucumber-preprocessor

Is it possible to skip dynamically one of the Cypress tests - meaning one feature file and with its step definitions?


I've a list of features files and the list of the related step definitions. Every feature file refers to some specific functionality of the website. According to some environment variables defined in package.json and representing the theme of the website, I might need to skip entirely some of the feature files (and obviously their step definition), due to missing feature for some specific theme.

To give some code examples:

  "test:cy:run:daylight": "PORT=9000 CYPRESS_THEME=daylight cypress run",
  "test:cy:run:darkness": "PORT=9001 CYPRESS_THEME=darkness cypress run",

feature files list:

daylight.feature
afternoon.feature
evening.feature
night.feature

with the relative definitions:

daylight.spec.js
afternoon.spec.js
evening.spec.js
night.spec.js

So in case of CYPRESS_THEME=darkness I would like to skip entirely from my testing process the features evening.feature and night.feature

How to do that? Ideas?

This example is with fake data, my real scenarios includes many more features and themes, so unluckily splitting test in different folders or using Cypress tag is not an efficient option.

Another not efficient idea I am thinking of is to put conditionals in every step definition Given, When and Then with the help of the detection of the Cypress.env('THEME') but obviously I would prefer not to follow this approach.

Anything else? Thanks


Solution

  • The correct answer would be to tag the tests and run only specific tags... if such a feature existed. I believe @mosaad is wrong on his second point; the --tag command line parameter merely adds meta data to the run from what I understand. It doesn't restrict which spec files get run.

    If I were you I'd just try to get creative with your folder structure. Alternatively you can implement this person's workaround, which seems a bit heavy to me but probably gets the job done.