我正在尝试重构包含太多可重复步骤的黄瓜方案。我想清理它,以便阅读更容易/更清洁。这是场景:
Feature: Sample Fruit Basket purchase
Scenario: Purchase a sample fruit basket after changing the fruits
Given That I am on the sample fruit basket page
When I add an apple
And I add a banana
And I add an orange
And I remove a pear
And I remove a plum
And I add a strawberry
And I add a straberry
Then .......
....
有什么方法可以清理添加/删除步骤吗?我在考虑一张桌子,但不确定是不是这样做,或者是否可以用桌子来完成。
感谢您的帮助。
答案 0 :(得分:0)
这有帮助吗?
Feature: Sample Fruit Basket purchase
Scenario: Purchase a sample fruit basket after changing the fruits
Given That I am on the sample fruit basket page
When I add fruits:
|apple|
|orange|
And I remove fruits:
|pear|
|plum|
And I add fruits:
|strawberry|
Then ....
您的步骤定义可能如下所示(请注意下面的I add fruits
步骤)
Given(/^That I am on the sample fruit basket page$/) do
pending # express the regexp above with the code you wish you had
end
When(/^I add fruits:$/) do |table|
# table is a Cucumber::Ast::Table
pending # express the regexp above with the code you wish you had
end
When(/^I remove fruits:$/) do |table|
# table is a Cucumber::Ast::Table
pending # express the regexp above with the code you wish you had
end
针对单张表进行了更新
Feature: Sample Fruit Basket purchase
Scenario Outline: Purchase a sample fruit basket after changing the fruits
Given That I am on the sample fruit basket page
When I add <addfruit>
And I remove <removefruit>
Then ...
Examples:
|addfruit|removefruit|
|orange|apple|
|pear|plum|