4

I would like to write a gherkin scenario that specifies a table of parameters but represents a test for every combination of values in the table.

For example:

Given I visit <site>
When I enter <search_str>
Then I see at least 1 result

Examples:
| site           | search_str     |
| google.com     | pierce brosnan |
| jeeves.com     | matt leblank   |
| duckduckgo.com | jeff goldblum  |

I would like every search_str to be used on every site, making a total of 9 tests - not 3 tests.

How should I define this scenario? Can multiple example tables be used per scenario?

1 Answer 1

4

I believe there is no support for multi-dimensional examples tables in Gherkin scenarios as you have described. Also keep in mind what BDD is largely for: being readable to the business. We developers have to be careful not to get too technical in the feature files ;)

That being said, I can think of a couple ways to solve this problem.

1.Write either the site or the search_str multiple times like:

Examples:  
| site           | search_str     |  
| google.com     | pierce brosnan |  
| google.com     | matt leblank   |  
| google.com     | jeff goldblum  |  
| jeeves.com     | matt leblank   |  

etc...

2.Write the gherkin separately for each site like:

Given I visit "google.com"  
When I enter <search_str>
Then I see at least 1 result  
Examples:  
| search_str     |  
| pierce brosnan |  
| matt leblank   |  
| jeff goldblum  |  

3.Table after one of the steps along with examples like:

Given I visit <site> 
| site           |  
| google.com     |  
| jeeves.com     |  
| duckduckgo.com |  
When I enter <search_str>  
Then I see at least 1 result  
Examples:  
| search_str     |  
| pierce brosnan |  
| matt leblank   |  
| jeff goldblum  | 
4
  • 2
    Someone please feel free to fix my code formatting... First time writing an answer on SO ¯_(ツ)_/¯ Commented Mar 19, 2018 at 20:41
  • 1
    u must guess it's gonna be me haha Commented Mar 20, 2018 at 0:00
  • 2
    all i actually did was remove ONE space between list number and description which stopped it being a "numbered list" format and that is what was preventing code view style format. Commented Mar 20, 2018 at 0:03
  • Haha, of course @MichaelDurrant :) I thought I was putting in the spacing mostly correctly, but I didn't know about a small mistake like that would be the root of the issue. Thanks! Commented Mar 20, 2018 at 13:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.