问题
I have recently seen a cucumber scenario outline like this. sorry for my bad example below. But the format is in this way. I really wonder if this type of format is supported by cucumber? The nested Data tables. Has any one used this type of nested Data table? If yes is this the below format?
Scenario Outline: Hello World
Given I am logged in as <user>
When I search for <searchTerm>
Then I add the following to my basket:
| <item1> |teapot|
| <item2> |Yorkshire tea|
Examples:
| user | searchTerm |
| Adam | Tea |
Can i make a data table like above
回答1:
That's not quite how they work.
The nested data tables are used by the step that the table is joined to. It's usually used to do multiple of the same thing, using the data table on the inside as an array. This can include headers, or no headers - depending on how you have written your step. Remember - it's all about communication.
As an example:
Scenario Outline: Hello World
Given I am logged in as <user>
When I search for <searchTerm>
Then I add the following to my basket:
| <item1> |
| <item2> |
Examples:
| user | searchTerm | item1 | item2 |
| Adam | Tea | teapot | Yorkshire tea |
回答2:
Updated Answer!!
As @kayle mentioned in his answer.. You can write following test scenario's
Scenario Outline: Hello World
Given I am logged in as <user>
When I search for <searchTerm>
Then I add the following to my basket:
| Teapot |
| Yorkshire tea |
Examples:
| user | searchTerm |
| Adam | Tea |
or
Scenario Outline: Hello World
Given I am logged in as <user>
When I search for <searchTerm>
Then I add the following to my basket:
| <item1> |
| <item2> |
Examples:
| user | searchTerm | item1 | item2 |
| Adam | Tea | Teapot| Yorkshire tea|
the second scenario will be useful if you want to add different items for each user. for example:
Scenario Outline: Hello World
Given I am logged in as <user>
When I search for <searchTerm>
Then I add the following to my basket:
| <item1> |
| <item2> |
Examples:
| user | searchTerm | item1 | item2 |
| Adam | Tea | Yorkshire tea | Teapot |
| Tom | Books | book1 | book2 |
Hope it's clear!!
来源:https://stackoverflow.com/questions/44198093/nested-examples-in-cucumber-scenario-outline-list-or-map-values