SpecFlow/Cucumber/Gherkin - Using tables in a scenario outline

后端 未结 2 1656
臣服心动
臣服心动 2020-12-31 04:20

Hopefully I can explain my issue clearly enough for others to understand, here we go, imagine I have the two following hypothetical scenarios:

Scenario: Filt         


        
2条回答
  •  南笙
    南笙 (楼主)
    2020-12-31 04:42

    Technically, I think you could try calling steps from within a step definition:

    Calling Steps from Step Definitions

    For example I think you could rewrite the

    Then I should see :
    | Output   |
    |  |
    

    To be a custom step like

    I should have output that contains 
    

    Where output is a comma separated list of expected values. In the custom step you could break the comma separated list into an array and iterate over it calling

    Then "I should see #{iterated_value}"
    

    You could use a similar technique to pass in lists of filters and filter values. Your example row for the king size test might look like

    | page       | filter                               | value       | output                           |
    | Sweet/List | Filter.KingSize, Filter.ContainsNuts | True, False | Yorkie King Size, Mars King Size |
    

    Or maybe

    | page       |                              filter-value-pairs | output                           |
    | Sweet/List | Filter.KingSize:True, Filter.ContainsNuts:False | Yorkie King Size, Mars King Size |
    

    That being said, you should perhaps take Darren's words to heart. I'm not really sure that this method would help the ultimate goal of having scenarios that are readable by non-developers.

提交回复
热议问题