Cucumber 使用类似步骤重构黄瓜步骤

Cucumber 使用类似步骤重构黄瓜步骤,cucumber,Cucumber,我试图重构一个包含太多可重复步骤的cucumber场景。我想把它整理一下,以便它更容易阅读。以下是场景: 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

我试图重构一个包含太多可重复步骤的cucumber场景。我想把它整理一下,以便它更容易阅读。以下是场景:

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 ....... 
  ....
有没有办法清理添加/删除步骤?我正在考虑一张桌子,但不确定这是一种方式,或者是否可以用桌子来做

非常感谢您的帮助。

这有帮助吗

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
步骤)

针对单个表格更新

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|
功能:购买果篮样本
场景概述:更换水果后购买一个果篮样本
鉴于我在果篮样本页面上
当我加上
然后我移除
然后。。。
示例:
|添加水果|移除水果|
|橘子苹果|
|梨李|

谢谢你,巴拉。这将减少步骤的数量。有没有一种方法可以同时使用一个表进行添加和删除?您可以使用一个带有场景大纲的表。我已经更新了我的答案。
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|