你有两个步骤 - 一个设置一些价值的领域,另外检查是否一些领域已经给定值:
[When(@"I set the '(.*)' value in the (.*) field")]
public void WhenISetTheValueInTheField(string value, string field)
{
// ...
}
[Then(@"The '(.*)' value is displayed in (.*) field")]
public void ThenTheValueIsDisplayedInField(string value, string field)
{
// ...
}
随着Specflow可以调用步骤从Step Definitions。所以基本上你需要一个高级的步骤来解释你的高级意图 - 验证所有给定的输入值是否正确显示。要通过值和验证数据,你可以使用一个表:
Then all input values are displayed correctly:
| InputValue | InputField | DisplayedValue | DisplayField |
| X | Y | X | Somewhere |
| Z | Y | Z | SomewhereElse |
这一步里,你可以调用的步骤,你已经为每一组数据:
[Then(@"all input values are displayed correctly:")]
public void ThenAllInputValuesAreDisplayedCorrectly(Table table)
{
foreach (var row in table.Rows)
{
var inputValue = row["InputValue"];
var inputField = row["InputField"];
When($"I set the '{inputValue}' value in the {inputField} field");
var displayedValue = row["DisplayedValue"];
var displayField = row["DisplayField"];
Then($"The '{displayedValue}' value is displayed in {displayField} field");
}
}
的好处在这里除了高级步骤之外,您将在输出中看到每个步骤的参数。