小 cucumber 声明是:
And Instruments,Shareprice,Quantities to be added are
|name |sal |address|
|xyz |100 |Greek |
|abc |200 |Italy |
步骤定义是:
@Given("My emp details are $")
public void my_emp_details_are(DataTable arg1) throws Throwable {
List<EMP> lstemp= arg1.asList(EMP.class);
}
生成异常: cucumber.runtime.CucumberException:没有这样的字段数据结构.EMP.emps
EMP 是具有 3 个字段的类:
嘿,我是 Java 新手,我看过 asList() 文档,但我不明白 公共(public)列表asList(类itemType)
类型参数: T - 列表项的类型 参数: itemType - 列表项的类型
最佳答案
作为替代方案,您可以获取一个 List 作为输入参数,而无需进一步转换。
@Given("My emp details are $")
public void my_emp_details_are(List<EMP> lstemp) throws Throwable {}
如果您的 EMP 有 3 个字段(使用 setter 方法)名称、sal 和地址
关于java - 如何将 cucumber.api.Datatable 转换为数据表中超过 2 col 的 List<MyClass>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29412203/