添加导致在步骤定义中传递不同值的步骤
Add step which results in a different value being passed in step definition
我的 Cucumber 测试中有以下步骤定义:
@When("Customer {string} connects, Negotiates, Sends DR")
public void customerConnectsNegotiatesSendsDR(String session) throws InterruptedException {
buildsAndSendRequestToAgd(session);
RequestMessage requestMessage=new RequestMessage("DataRequest","1");
requestMessageBuilder.build(requestMessage).ifPresent(sender);
我想更新这个,这样我也可以有步骤 @When("Customer {string} connects, Negotiates, Sends DR for snapshot only")
。这样做,RequestMessage("DataRequest","1")
将变为 RequestMessage("DataRequest","0")
。
我知道我可以更新 @When("Customer {string} connects, Negotiates, Sends DR")
步骤以采用 0 或 1 的参数,但这需要我在使用它的所有功能文件中进行更新。我想知道是否有一种更简单的方法可以将值默认为 1,但如果使用步骤 @When("Customer {string} connects, Negotiates, Sends DR for snapshot only")
,它会选择 0.
这是否可能或是否有公认的方法来做到这一点?
我还没有尝试过,但是步骤定义中支持正则表达式:https://cucumber.io/docs/cucumber/step-definitions/#expressions,捕获组作为参数传递给 stepdef 方法,所以也许像下面这样的东西会起作用:
@When("Customer {string} connects, Negotiates, Sends DR( for snapshot only)?")
public void customerConnectsNegotiatesSendsDR(String session, String snapshotOnly) throws InterruptedException {
...
}
我的 Cucumber 测试中有以下步骤定义:
@When("Customer {string} connects, Negotiates, Sends DR")
public void customerConnectsNegotiatesSendsDR(String session) throws InterruptedException {
buildsAndSendRequestToAgd(session);
RequestMessage requestMessage=new RequestMessage("DataRequest","1");
requestMessageBuilder.build(requestMessage).ifPresent(sender);
我想更新这个,这样我也可以有步骤 @When("Customer {string} connects, Negotiates, Sends DR for snapshot only")
。这样做,RequestMessage("DataRequest","1")
将变为 RequestMessage("DataRequest","0")
。
我知道我可以更新 @When("Customer {string} connects, Negotiates, Sends DR")
步骤以采用 0 或 1 的参数,但这需要我在使用它的所有功能文件中进行更新。我想知道是否有一种更简单的方法可以将值默认为 1,但如果使用步骤 @When("Customer {string} connects, Negotiates, Sends DR for snapshot only")
,它会选择 0.
这是否可能或是否有公认的方法来做到这一点?
我还没有尝试过,但是步骤定义中支持正则表达式:https://cucumber.io/docs/cucumber/step-definitions/#expressions,捕获组作为参数传递给 stepdef 方法,所以也许像下面这样的东西会起作用:
@When("Customer {string} connects, Negotiates, Sends DR( for snapshot only)?")
public void customerConnectsNegotiatesSendsDR(String session, String snapshotOnly) throws InterruptedException {
...
}