badeball / cypress-cucumber-preprocessor

Run cucumber/gherkin-syntaxed specs with Cypress
MIT License
1.32k stars 149 forks source link

Step definitions with different keyword but same expression conflict with each other #662

Closed aryzing closed 2 years ago

aryzing commented 2 years ago

Current behavior

Step definitions with the same expression but different keyword conflict with each other. Seems that the first one that is defined in the file is the one that's used while running the tests.

For example, given these two step definitions,

Given("the user is authenticated", function () {
  // code to set up user authentication
});

// Later in the file, this next `Then` is defined for a different scenario

Then("the user is authenticated", function () {
  // code that checks the user is authenticated
});

Clearly, the above step definitions run significantly different code. However, when both are defined in the same file, the first one (Given), is always run for all scenarios with any step with the text "the user is authenticated".

Desired behavior

Each step definition should only run for the keyword it is defined with.

Test code to reproduce

https://github.com/aryzing/repro-cypress-cucumber-preprocessor-same-name-bug

Versions

aryzing commented 2 years ago

Seems that vanilla Cucumber behaves the same way, so I'll close this.