badeball / cypress-cucumber-preprocessor

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

Common steps feature is not working #745

Closed CharalamposSam closed 2 years ago

CharalamposSam commented 2 years ago

Current behavior

I have downloaded the project of Alapan, from the following link: https://github.com/alapanme/Cypress-Automation I executed "login.feature" test scenario and is working fine.

scenarioWorking

I have added a common folder under the e2e folder and inside that I have add a common.js file. Inside common.js, I have import cucumber and added the first step from the scenario (meaning that this step does not exist anymore at login.js)

commonJS

Executing the scenario again, this is what I get:

scenarioNotWorking

Desired behavior

This should be working, as it was working before Cypress 10

Test code to reproduce

Versions

Checklist

badeball commented 2 years ago

Given that you're following @alapanme's examples, I think you should ask them about the issue. Open up a ticket in their tracker.

CharalamposSam commented 2 years ago

@badeball the provided code is just an example. If you need from me to upload my own example, no problem. The question is if the "Common Steps" feature exists in version 11.0.0 for Cypress 10. If yes, does it have different syntax from version 4.3.1? If no, will it be implemented?

Thank you in advance.

badeball commented 2 years ago

These questions are answered in #689 (Upgrade guide from TheBrainFamily/cypress-cucumber-preprocessor). TLDR: Yes, you can still have common steps.

uaru commented 2 years ago

I am quite confused, too, and I did not manage to get the common steps to work.

badeball commented 2 years ago

I might be able to help if you provide me a reproducible example, IE. a Git repo.

tinu-harbr commented 2 years ago

@uaru I have below snippet on my package.json. My common step definitions are undercypress/e2e/common/ folder and feature specific steps are under sub folder on cypress/e2e/features/.

 "cypress-cucumber-preprocessor": {
    "nonGlobalStepDefinitions": true,
    "stepDefinitions": [
      "cypress/e2e/common/*.{js,ts}",
      "cypress/e2e/features/**/*.{js,ts}"
    ]
  },
fras2560 commented 2 years ago

I am running into a situation where a global step is missing implementation in one test and another global step (in same file) is used in another test. Any idea on what I could be doing wrong? I added the file quite explicitly to the step definitions.

  "stepDefinitions": [
    "[filepath]/**/*.{js,ts}",
    "[filepath].{js,ts}",
    "cypress/features/global/**/*.{js,ts}",
    "cypress/features/global/login.{js,ts}"
  ]

EDIT

I was able to figure out the issue. The one test imported from the file with the global steps and other did not import. I am using webpack. Hope this helps if anyone else runs into the issue.

badeball commented 2 years ago

@fras2560, 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).

uaru commented 2 years ago

Thank you, @tinu-harbr. I copied your snippet. I think I had something similar before, but this time it worked.

I extracted the configuration and example from my project, if anyone is interested.

https://github.com/uaru/cypress-config-example.git