Nested examples in cucumber scenario outline - List or Map values

寵の児 提交于 2021-02-07 20:53:22

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!