0

I have a website that opens a dialog where you can add rows of information like a spreadsheet. There is a total amount that shows in the window that adds up a column of items in the table (before the user clicks save). When the user is done editing the information, they click save, which closes the window and sends off the information to a server, which processes the data and updates the front end with more calculated values based on the data entered.

Using Gherkin, Cucumber, and nightwatch.js, I need to test the total display in the window before the user clicks save, but I also need to test the values outside of the window after the user clicks save. But from what I understand of Gherkin, having two when statements is bad practice. But if i split it up into two Scenarios, they would rely on each other.

What I have now:

Scenario: Modify data in the data window
  Given the window is open
  When I modify the data inside the window
  Then the total amount should reflect that change
  When I click save
  Then the data should save
   And the processed data should reflect my changes
swaplink
  • 43
  • 2
  • 8
  • 2
    Not sure where you got that it's a bad practice to have 2 when statements. As per me your scenario looks good and does not need any modifications. – supputuri Jul 05 '19 at 21:21
  • @supputuri The whole point of the question is that I can't find a way to get rid of the second When statement. – swaplink Jul 05 '19 at 21:24
  • I got that, but you don't have to get rid of the second scenario. Still if you wish to make them 2 scenario, you can check `textContext` or using hook/env file to share the details between the scenarios. – supputuri Jul 05 '19 at 21:44
  • @supputuri What is textContext? – swaplink Jul 05 '19 at 22:42
  • Sorry, it's testcontext. That was a typo. – supputuri Jul 06 '19 at 02:15

1 Answers1

0

I would write the scenario thusly:

Scenario: Modify data in the data window
  Given the window is open
  When I modify the data inside the window
  Then the total amount should reflect that change
  And I click save
  And the data should save
  And the processed data should reflect my changes

-but- there's no reason you can't make it two scenarios since they would run in sequence

Scenario: Modify data in the data window
  Given the window is open
  When I modify the data inside the window
  Then the total amount should reflect that change

Scenario: Save data in the data window
  Given I have modified data inside the window
  When I click save
  Then the data should save
   And the processed data should reflect my changes
Bill Hileman
  • 2,798
  • 2
  • 17
  • 24
  • The latter would be the way to go. As I understand Gherkin, I don't think clicking save in a `Then` statement would be best practice: `And I click save` – swaplink Jul 08 '19 at 19:41
  • Agreed. Second is better, clearer. I have also been taught to avoid multiple when/then in one scenario. – Bill Hileman Jul 08 '19 at 20:08