如何在 cucumber-jvm 步骤之间传递变量
为了在步骤之间传递变量,我让步骤方法属于同一类,并使用该类的字段作为传递的信息。
下面是一个示例:
Feature: Demo
Scenario: Create user
Given User creation form management
When Create user with name "TEST"
Then User is created successfully
包含步骤定义的 Java 类:
public class CreateUserSteps {
private String userName;
@Given("^User creation form management$")
public void User_creation_form_management() throws Throwable {
// ...
}
@When("^Create user with name \"([^\"]*)\"$")
public void Create_user_with_name(String userName) throws Throwable {
//...
this.userName = userName;
}
@Then("^User is created successfully$")
public void User_is_created_successfully() throws Throwable {
// Assert if exists an user with name equals to this.userName
}
我的问题是,在步骤之间共享信息是否是一种好的做法?或者最好将功能定义为:
Then User with name "TEST" is created successfully