我需要自动化一些网络服务,我为此创建了一些方法,并且我想使用 Cucumber 来实现这一点,但我不知道如何在下一步中使用返回值。
所以,我有这个功能:
Feature: Create Client and place order
Scenario: Syntax
Given I create client type: "66"
And I create for client: "OUTPUTVALUEfromGiven" an account type "123"
And I create for client: "OUTPUTVALUEfromGiven" an account type "321"
And I want to place order for: "outputvalueFromAnd1"
我有这个步骤:
public class CreateClientSteps {
@Given("^I create client type: \"([^\"]*)\"$")
public static String iCreateClient(String clientType) {
String clientID = "";
System.out.println(clientType);
try {
clientID = util.createClient(clientType);
} catch (IOException e) {
e.printStackTrace();
}
return clientID;
}
@And("^I create for client: \"([^\"]*)\" an account type \"([^\"]*)\"$")
public static String createAccount(String clientID, String accountType) {
String orderID = "";
try {
orderID = util.createAccount(clientID,accountType);
} catch (IOException e) {
e.printStackTrace();
}
return orderID;
}
}
有什么方法可以一步一步使用返回值吗?
谢谢你!
步骤之间共享状态(这就是我解释您的问题的方式)不是通过检查返回值来完成的。这是通过在实例变量中设置值然后在另一个步骤中读取该实例变量来完成的。
为了实现这一目标,我将更改您的步骤:
public class CreateClientSteps {
private String clientID;
private String orderID;
@Given("^I create client type: \"([^\"]*)\"$")
public void iCreateClient(String clientType) {
System.out.println(clientType);
try {
clientID = util.createClient(clientType);
} catch (IOException e) {
e.printStackTrace();
}
}
@And("^I create for client: \"([^\"]*)\" an account type \"([^\"]*)\"$")
public void createAccount(String clientID, String accountType) {
try {
orderID = util.createAccount(clientID, accountType);
} catch (IOException e) {
e.printStackTrace();
}
}
}
我改变的事情是
- 用于共享状态的两个字段 - 其他步骤可以稍后读取这些值
- 非静态方法 - Cucumber 为每个场景重新创建步骤类,因此我不希望字段是静态的,因为这意味着它们的值会在场景之间泄漏
这是在同一类中的步骤之间共享状态的方式。还可以在不同类的步骤之间共享状态。情况有点复杂。询问您是否有兴趣。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)