如何将Cucumber.api.Datable转换为List< MyClass>数据表中有超过2个col [英] 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 |
步骤def为:
@Given("My emp details are $")
public void my_emp_details_are(DataTable arg1) throws Throwable {
List<EMP> lstemp= arg1.asList(EMP.class);
}
生成的异常:
cuming.runtime.CucumberException:无此类字段datastructure.EMP.emps
Exception Generated: cucumber.runtime.CucumberException: No such field datastructure.EMP.emps
EMP是具有3个字段的类:
EMP is Class with 3 fields:
嘿,我是Java新手见asList()文档我不理解
公共列表asList(Class itemType)
Hey i am new to Java I have seen asList() Documentation i didnt understand public List asList(Class itemType)
类型参数:
T-列表项的类型
参数:
itemType-列表项的类型
Type Parameters: T - the type of the list items Parameters: itemType - the type of the list items
推荐答案
或者,您可以获取列为输入参数,无需进一步转换。
As an alternative, you can get a List as the input parameter without further conversion.
@Given("My emp details are $")
public void my_emp_details_are(List<EMP> lstemp) throws Throwable {}
如果您的EMP有3个字段(设置方法)姓名,工资和地址
if you EMP has the 3 fields (with setter methods) name, sal and address
这篇关于如何将Cucumber.api.Datable转换为List< MyClass>数据表中有超过2个col的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!