Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicate step definitions should not be allowed #678

Closed
andyg101 opened this issue Mar 15, 2022 · 21 comments
Closed

Duplicate step definitions should not be allowed #678

andyg101 opened this issue Mar 15, 2022 · 21 comments

Comments

@andyg101
Copy link

Current behavior

Currently the pre-processor allows duplicate step definition implementation to be present and just silently picks the first step definition it finds. This is counter to my understanding of good practice with BDD frameworks where a single step definition should have a single implementation so that the natural language gherkin phrases have a consistent and deterministic behaviour.

Note I'm just considering the general case here. I'm not saying that if you have a custom step definition for a specific feature file in a matching folder it couldn't match an existing common step (although I would argue that is probably bad practice from a BDD perspecive).

Desired behavior

I think the framework should reject / refuse to process a set of feature files if it cannot resolve step definitions down to a single implementation.

Test code to reproduce

Feature file:

Feature: A feature with a duplicate step definition

This demonstrates the sisue with duplicate step definition implementations 
which are not currently detected by the pre-processor.

  Scenario: Duplicate step definition implementations should fail
     Given a step definition with a duplicate implementation

Implementation:

const { Given } = require("cypress-cucumber-preprocessor/steps")

Given(/^a step definition with a duplicate implementation$/, function () {
  cy.log("This step will get executed becacuse it appears first")
}); 


Given(/^a step definition with a duplicate implementation$/, function () {
  cy.log("This step will note get executed becacuse it appears second")
}); 

Versions

  • Cypress version: 8.3.1
  • Preprocessor version: 4.3.1
  • Node version: 14.17.3
@lgandecki
Copy link
Collaborator

Hello

Could you please check how pure cucumberjs solves this problem? We would like to match cucumber behavior as much as possible

@badeball
Copy link
Owner

It's not allowed in cucumber-js (I've replicated that behavior in my fork).

@andyg101
Copy link
Author

Thanks for confirming that for me @badeball . I've opened a PR with a proposed fix for this. Please let me know if you think it is suitable or needs additional work.

@badeball
Copy link
Owner

Due to personal reasons, the previous maintainers of this package are stepping down and handing the reigns over to me, a long-time contributor to the project and a user of it myself. This is a responsibility I'm very excited about. Furthermore, I'd like to thank @lgandecki ++ for all the work that they've done so far.

Read more about the transfer of ownership here.

The repository has however moved and all outstanding issues are being closed. This is not a reflection of the perceived importance of your reported issue. However, if after upgrading to the new version, you still find there to be an issue, feel free to open up another ticket or comment below. Please make sure to read CONTRIBUTING.md before doing so.

@JomyGeo
Copy link

JomyGeo commented Jun 28, 2022

@badeball I am facing Multiple-step definitions found error when we have same step definition description in two different feature files.

For example,

I have two different feature files like login.feature, forgetPassword.feature. I have a common step Given(''Open the browser and load the URL''), in both feature files.

How to handle this scenario? i believe this error will display only when we have duplicate steps in same feature file, not for two different feature files. Please provide your thoughts on this

#Cypress 10.2

@badeball
Copy link
Owner

@JomyGeo, you're making it impossible for me to help you. You have to show me an example that I can correct (and don't make it difficult by doing that with screenshots or large bodies of code, give me a cloneable repository that illustrates your folder structure).

@JomyGeo
Copy link

JomyGeo commented Jun 30, 2022

@badeball
I have created a sample project which illustrates the folder structure of my project.
Please Use this repo

@JomyGeo
Copy link

JomyGeo commented Jul 4, 2022

@badeball Could you please check the above repo and provide us an update for the same

@badeball
Copy link
Owner

badeball commented Jul 4, 2022

@JomyGeo #750 (comment)

@JomyGeo
Copy link

JomyGeo commented Jul 7, 2022

@badeball Do we have an option to pass stepDefinition file path on runtime (Terminal) as we pass it for Spec path(.Feature file)?

Because when I set the Stepdefiition as a global pattern in package.json then Before() Hook runs every time which is not related to that spec file. #750

Current behaviour :
I have to pass the exact step definition path in package.json to overcome this issue

Expected behaviour :
Passing step definition path in run time (Terminal). So that it will be executed the hook within the Specified step definition path

@JomyGeo
Copy link

JomyGeo commented Jul 8, 2022

@badeball I couldn't override the Environment variables in command line. Correct me , if i am wrong

Example : cypress run -e tags='@demo',filterSpecs=true --browser='electron'

image

@badeball
Copy link
Owner

badeball commented Jul 8, 2022

Looks right, but again it's difficult to tell because you're giving me an example of what you're doing and not exactly what you're doing.

@JomyGeo
Copy link

JomyGeo commented Jul 8, 2022

@badeball Please check the below Repo

run command :cypress run -e tags='@Login',filterSpecs=true --browser='electron'

@badeball
Copy link
Owner

badeball commented Jul 8, 2022

The command does set the environment variables tags=@Login and filterSpecs=true.

@JomyGeo
Copy link

JomyGeo commented Jul 11, 2022

@badeball It didn't work for me. All i want here is to override the stepDefinitions and filterSpecs environment variable values in runtime. But it is not working for me. Cypress script executing based on the value in cypress.config.js , not run time.

cypress run -e stepDefinitions='cypress/e2e/StepDefinitions/Product_Steps/**/*.js' --browser='electron'
cypress run command :cypress run -e tags='@Login',filterSpecs=true --browser='electron'

@badeball
Copy link
Owner

Well, what have to tried so far? I only see two commands which sets each separately, how have you tried to set them simultaneously?

@JomyGeo
Copy link

JomyGeo commented Jul 11, 2022

@badeball I run the below commands seperately , Not at same time

cypress run -e stepDefinitions='cypress/e2e/StepDefinitions/Product_Steps/**/*.js' --browser='electron'
cypress run command :cypress run -e tags='@Login',filterSpecs=true --browser='electron'

@badeball
Copy link
Owner

Then I don’t understand what’s the issue here.

@JomyGeo
Copy link

JomyGeo commented Jul 11, 2022

The problem here is that I could not override the value in runtime. In some cases, I want to change the stepDefinition folder value im runtime. The below code didn't work for me. Please guide to sort out this problem

cypress run -e stepDefinitions='cypress/e2e/StepDefinitions/Product_Steps/**/*.js' --browser='electron'

@badeball
Copy link
Owner

Saying "it didn't work" simply doesn't help me and I give up now. This wasn't a support forum to begin with and you've turned out to be too difficult to deal with. I recommend that you try SO.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants