Cucumber 场景大纲 Scenario Outlines

引用链接:https://github.com/cucumber/cucumber/wiki/Scenario-Outlines

 

    1.  script/cucumber --i18n zh-CN  
    2.       | feature          | "功能"       |  
    3.       | background       | "背景"       |  
    4.       | scenario         | "场景"       |  
    5.       | scenario_outline | "场景大纲"     |  
    6.       | examples         | "例子"       |  
    7.       | given            | "* ""假如" |  
    8.       | when             | "* ""当"  |  
    9.       | then             | "* ""那么" |  
    10.       | and              | "* ""而且" |  
    11.       | but              | "* ""但是" |  
    12.       | given (code)     | "假如"       |  
    13.       | when (code)      | "当"        |  
    14.       | then (code)      | "那么"       |  
    15.       | and (code)       | "而且"       |  
    16.       | but (code)       | "但是"       | 

Copying and pasting scenarios to use different values quickly becomes tedious and repetitive:

Scenario: eat 5 out of 12
  Given there are 12 cucumbers
When I eat 5 cucumbers
Then I should have 7 cucumbers

Scenario: eat 5 out of 20
  Given there are 20 cucumbers
When I eat 5 cucumbers
Then I should have 15 cucumbers

Scenario outlines allow us to more concisely express these examples through the use of a template with placeholders, using Scenario Outline, Examples with tables and < > delimited parameters:

Scenario Outline: eating
  Given there are <start> cucumbers
When I eat <eat> cucumbers
Then I should have <left> cucumbers

Examples:
    | start | eat | left |
    |  12   |  5  |  7   |
    |  20   |  5  |  15  |

The Scenario Outline steps provide a template which is never directly run. A Scenario Outline is run once for each row in the Examples section beneath it (not counting the first row).

The way this works is via placeholders. Placeholders must be contained within < > in the Scenario Outline's steps. For example:

Given <I'm a placeholder and I'm ok>

The placeholders indicate that when the Examples row is run they should be substituted with real values from the Examples table. If a placeholder name is the same as a column title in the Examples table then this is the value that will replace it.

You can also use placeholders in Multiline Step Arguments.

IMPORTANT: Your step definitions will never have to match a placeholder. They will need to match the values that will replace the placeholder

So when running the first row of our example:

Examples:
  | start | eat | left |
  |  12   |  5  |  7   |

The scenario that is actually run is:

Scenario: controlling order
  Given there are 12 cucumbers      # <start> replaced with 12
When I eat 5 cucumbers            # <eat> replaced with 5
Then I should have 7 cucumbers    # <left> replaced with 7

----------------------------------------------------------------------------------------

场景大纲:输入产品ID并验证
  假如 打开首页
  而且 输入<<ProdID>> #双尖括号
 
例子:产品ID                  #"产品ID"是自定义的
    |ProdID|
    |111111|
    |222222|
    |333333|
    |444444|

转载于:https://www.cnblogs.com/dami520/p/3243522.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值