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

一世执手 提交于 2019-12-08 11:19:43

问题


Gherkin Statement is :

And Instruments,Shareprice,Quantities to be added are
|name    |sal   |address|
|xyz     |100   |Greek  |
|abc     |200   |Italy  |   

Step def is :

@Given("My emp details are $")
public void my_emp_details_are(DataTable arg1) throws Throwable {
    List<EMP> lstemp= arg1.asList(EMP.class);
}

Exception Generated: cucumber.runtime.CucumberException: No such field datastructure.EMP.emps

EMP is Class with 3 fields:

Hey i am new to Java I have seen asList() Documentation i didnt understand public List asList(Class itemType)

Type Parameters: T - the type of the list items Parameters: itemType - the type of the list items


回答1:


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 {}

if you EMP has the 3 fields (with setter methods) name, sal and address



来源:https://stackoverflow.com/questions/29412203/how-to-convert-cucumber-api-datable-to-listmyclass-with-more-than-2-col-in-dat

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!