Search code examples
javacucumber-jvm

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


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


Solution

  • 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