I updated from Cucumber-JVM 2.4.0 to 3.0.2 in my pom.xml
and DataTables started throwing this exception:
io.cucumber.datatable.UndefinedDataTableTypeException: Can't convert DataTable to List< jcucumberng.steps.pojos.Income >. Please register a DataTableType with a TableEntryTransformer or TableRowTransformer for class jcucumberng.steps.pojos.Income
I changed all my imports to
import io.cucumber.datatable.DataTable;
I did an mvn clean install
and compilation was successful but steps involving DataTables no longer work after the update.
Current code:
// Feature
When I Enter My Regular Income Sources
| name | amount | frequency |
| Salary | 25000 | every 2 weeks |
// Stepdef
@When("^I Enter My Regular Income Sources$")
public void I_Enter_My_Regular_Income_Sources(DataTable dataTable) throws Throwable {
List<Income> incomes = dataTable.asList(Income.class);
// More code
}
// Custom type
public class Income {
private String name = null;
private String amount = null;
private String frequency = null;
public Income(String name, String amount, String frequency) {
this.name = name;
this.amount = amount;
this.frequency = frequency;
}
// Getters and setters
}
Is there a new way to use the DataTables in Cucumber-JVM v3.x.x?
Migrating from v2.x.x to v3.x.x for DataTable
Posting my answer to serve as reference for those who may encounter the same. For their release announcement, click here.
I decided to put
DataTableConfigurer.java
in its own package so it does not mix with my stepdefs:Runner:
DataTableConfigurer:
I had another custom domain type
Expense
(which happened to have the same fields), so I just registered it again based on the example.It has been totally revamped. XStream has been removed , so earlier code will not work.
You will need to add logic for datatable and parameter conversion. Refer to these - https://github.com/cucumber/cucumber/tree/master/datatable and https://github.com/cucumber/cucumber/tree/master/cucumber-expressions . Place below class code inside a package defined in the glue option.
UPDATED Imports... Not all are required, keep what is relevant