0

Is it possible to have nested scenario outlines in Behat (Gherkin)

e.g. do all of the below for a different set of Examples

 Scenario Outline: Some Outline
   Given step one with <var1>
  When step two with <var2>
   Then step three

Examples:
   | var1 | var2 |
   | 1    | 4    |
   | 2    | 5    |
   | 3    | 6    |
paullb
  • 4,293
  • 6
  • 37
  • 65

1 Answers1

1

It's not entirely clear what you mean. The scenario outline you wrote looks fine. It will end up doing the following:

Given step one with 1
When step two with 4
Then step three

Given step one with 2
When step two with 5
Then step three

Given step one with 3
Then step two with 6
Then step three

But it sounds like perhaps you want to do more like this:

Given step one with 1
And step one with 2
And step one with 3
Then step two with 4
And step two with 5
And step two with 6
Then step three

This is where inline tables come into play. You would do:

Scenario: Some Scenario
Given step one
  | var |
  | 1   |
  | 2   |
  | 3   |
When step two
  | var |
  | 4   |
  | 5   |
  | 6   |
Then step three

You will need to write the "step one" and "step two" steps in the context file to accept a single TableNode argument and iterate over it with foreach(){}.

romulusnr
  • 111
  • 4