0
votes

Is it possible to write a scenario outline in gherkin which has an assertion step which won't be needed in all the examples?

The scenario will have two assertion steps to test a table which can be toggled.

  1. Check that a data table is displayed.
  2. If it is then check the values are correct.

For #2 when the table is toggled off, then the second step won't need to run so I am wondering if I can use a data table and leave the value empty

Example below:

Scenario Outline: Toggle graph and test data
Given I have "<Data>" data set
When I toggle the grid "<toggle>"
Then the grid is "<display>"
And all grid cells contain "<gridValues>"
Examples:
  | Data       | toggle | display   | gridValues |
  | 240        | On     | displayed | 240        |
  | 240        | Off    | hidden    |            |
  | null data  | On     | displayed | -          |
  | null data  | Off    | hidden    |            |

The "gridValues" will only be used in two of the scenarios.

Is there a better way of writing this?

1
Then you should write another Scenario. A common phrase used in such case is don't code your feature file. (in an ideal world) The sentences are written before any code design decision has been chosen. At this stage it might not even be decided that there will be a toggle. (this heavily depends on what should be achieved) - SubOptimal
In line with @SubOptimal; write different scenarios. Your expectation will be different if the toggle is on or off; you could test both of those. (Given the toggle is on, the data should be shown and validated; Given it's off, it should not be shown) - Marit

1 Answers

1
votes

Yes there is a better way of writing this. Try and write a scenario that explains WHAT you are doing and WHY its important, rather than one that is full of details that explain how you do something but actually reveals nothing at all about what you are doing.

Some questions to help you do this

  • What does the data in the data set represent
  • What is the grid
  • Why would we toggle the grid? Whats the point?
  • Why are you even writing this scenario?

etc. etc.

Try popping the Why stack with yourself and see if you can uncover the WHAT and WHY.