引用链接:https://github.com/cucumber/cucumber/wiki/Scenario-Outlines
script/cucumber –i18n zh-CN
| feature | “功能” |
| background | “背景” |
| scenario | “场景” |
| scenario_outline | “场景大纲” |
| examples | “例子” |
| given | “* “, “假如” |
| when | “* “, “当” |
| then | “* “, “那么” |
| and | “* “, “而且” |
| but | “* “, “但是” |
| given (code) | “假如” |
| when (code) | “当” |
| then (code) | “那么” |
| and (code) | “而且” |
| 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|