如何将数据表中超过 2 列的 cucumber.api.Datable 转换为 List<MyClass>

How to convert cucumber.api.Datable to List<MyClass> with more than 2 col in datatable

小黄瓜声明是:

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: 没有这个字段 datastructure.EMP.emps

EMP 是 Class,有 3 个字段:

嘿,我是 Java 的新手,我看过 asList() 文档,我不明白 public List asList(Class itemType)

类型参数: T - 列表项的类型 参数: itemType - 列表项的类型

作为替代方案,您可以将 List 作为输入参数,而无需进一步转换。

@Given("My emp details are $") 
public void my_emp_details_are(List<EMP> lstemp) throws Throwable {}

如果您的 EMP 有 3 个字段(使用 setter 方法)name、sal 和 address