Step definition folder structure in cypress cucumber preprocessor

Viewed 1578

Versions

  • Cypress version: 8.4.0
  • Preprocessor version: 4.2.0
  • Node version: 12.18.2

Hi all, apologies if this is a stupid question, I'm quite new/noob with cypress, let alone cypress + cucumber.

So I wrote some automation tests in cucumber, and they work fine. I have the feature files in the integration folder, and the step definition folders in the integration folder too. Now I'm trying to have some structure where under integration I have a folder named step_definitions (will show better in screenshot).

folder structure

In package.json I put the following:

"cypress-cucumber-preprocessor": { "nonGlobalStepDefinitions": true, "nonGlobalStepBaseDir": "step_definitions", "commonPath": "common", "stepDefinitions": "step_definitions" }

When I try to run the tests, I get the below error:

Error: We've tried to resolve your step definitions at step_definitions, but that doesn't seem to exist. As of version 2.0.0 it's required to set step_definitions in your cypress-cucumber-preprocessor configuration. Look for nonGlobalStepDefinitions and add stepDefinitions right next to it. It should match your cypress configuration has set for integrationFolder. We no longer rely on getting information from that file as it was unreliable and problematic across Linux/MacOS/Windows especially since the config file could have been passed as an argument to cypress.

Any pointers are appreciated :)

2 Answers

It seems to me that the problem in your case in "stepDefinitions": "step_definitions" have you tried to give the full path like "stepDefinitions": "cypress/integration/step_definitions"?

You should set nonGlobalStepDefinitions to false or remove this setting, as you don't have a separate folder for the step_definitions but it is inside the integration folder instead.

So, in order to use your structure, please modify that section in the package.json file to:

"cypress-cucumber-preprocessor": { "commonPath": "cypress/integration/step_definitions/common", "stepDefinitions": "cypress/integration/step_definitions" }

That would be enough. It works.

Related