David
David

Reputation: 1

Scenario outline in gherkin

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?

Upvotes: 0

Views: 690

Answers (1)

diabolist
diabolist

Reputation: 4109

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.

Upvotes: 1

Related Questions