0

I have a question since i started o use cucumber with cypress. According to cucumber syntax we can write scenarios like this:

Feature: Background Section

   Scenario: ex #1
     When counter is incremented
     Then counter equals 1

   Scenario: ex #2
     When counter is incremented
     When counter is incremented
     Then counter equals 2
     
   Scenario: ex #3
     When counter is incremented
     Then counter equals 3

Question: If When counter is incremented is used in each scenario, does this mean that the code that is write in ex 1 will override the When counter is incremented from ex 2?
Question reason: I had a situation in cypress when the tests was working separately but if i put all the scenarios to run then a test failed, and only making different the titles of each when.then.given my tests passed. So i assume the the titles have an importance. Who faced with the same issues?

Asking
  • 3,487
  • 11
  • 51
  • 106

1 Answers1

0

You can design those steps to increment or not.

Seems like you are missing basic understanging of layers

  1. Gherkin
  2. Cucumber
  3. Cypress

"When counter is incremented" Is execued everytime with the same code underneath, so if you declare your counter inside that step:

let counter = 0

it will reset to 0 everytime.

For me every .feature file should be able to pass on it's own, as e2e can be very large and take up to few hours, so imagine you want to re-run specific scenario that is dependent on other tests.

Adrian
  • 65
  • 1
  • 8
  • so will have an importance if i will have `When counter is incremented` on different scenarious? Will the previous `When counter is incremented` override the next `When counter is incremented`? Taking into account that the title is the same or the title does not play a role in terms of the test result? – Asking Mar 19 '22 at 20:06
  • I would say more important is were you declare your variable, in most cases it will be overwritten, but I would strongly recommend to make some proof of concept. Gherkin with Cucumber are very flexible thus it's difficult to answer your question as there is many unknowns – Adrian Mar 24 '22 at 08:52
  • could you help with this please https://stackoverflow.com/questions/71599765/test-the-new-error-message-with-cypress – Asking Mar 24 '22 at 09:25