我目前正在将 selenium 与 Java 一起使用,并希望实现 Cucumber 以使测试脚本更具可读性。
当前在将参数传递给 java 方法时遇到问题,其中 Enum 应为参数。
我还想知道在迁移当前框架之前,cucumber-java 是否还有其他已知的限制。
因为我是 cucumber 新手 如果有人知道详细学习 cucumber 的好来源,请给我一个链接。
最佳答案
答案是:是的
您可以在您的场景中使用所有类型的不同类型:原始类型、自己的类 (POJO)、枚举……
设想 :
Feature: Setup Enum and Print value
In order to manage my Enum
As a System Admin
I want to get the Enum
Scenario: Verify Enum Print
When I supply enum value "GET"
步骤定义代码:
import cucumber.api.java.en.When;
public class EnumTest {
@When("^I supply enum value \"([^\"]*)\"$")
public void i_supply_enum_value(TestEnum arg1) throws Throwable {
testMyEnum(arg1);
}
public enum TestEnum {
GET,
POST,
PATCH
}
protected void testMyEnum(TestEnum testEnumValue) {
switch (testEnumValue) {
case GET:
System.out.println("Enum Value GET");
break;
case POST:
System.out.println("Enum Value POST");
break;
default:
System.out.println("Enum Value PATCH");
break;
}
}
}
让我知道你在做什么。我可以试着帮你。
关于selenium - 是否可以将 Java-Enum 作为参数从 cucumber 特征文件中传递,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34718083/