cucumber-jvm: DataTable - Automatic conversion to custom type stopped working
Summary
After updating cucumber-testng (and subsequently all transient dependencies) from 2.4.0 to 3.0.2 in pom.xml, automatic conversion for datatables using custom types stopped working and now throws UndefinedDataTableTypeException.
Expected Behavior
Only change required is to update imports to import io.cucumber.datatable.DataTable; and tests to run as per usual.
Current Behavior
Getting this exception from steps that worked prior to update:
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
// 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
}
Possible Solution
Show more useful comments/javadocs for DataTable specially if updating from v2.x.x to v3.x.x for major changes to its usage. Allow easier automatic conversion like before.
Context & Motivation
A revamp of the DataTable usage will break a lot of existing tests and can totally prevent people from updating to v3.x.x. It also outdates a lot of widely available tutorials and references.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 5
- Comments: 39 (31 by maintainers)
I’ve got a pending PR for this (haven’t pushed yet). I’m reopening since I plan to fix it next week.
Context: I just ran a public training where a few people remarked that while the new data tables are great, they do require more boilerplate/configuration code. I think I’ve found a pragmatic middle ground, where you’ll still need to register a
DataTableType, but doing so will be a one-liner.You are looking for a quick fix for what exactly? The context of this issue allows for a number of problems.
To wit the default table converters receive the same information that XStream would. So if anything you can use XStream as the default converter though you may have to copy the exact configuration from Cucumbers v2.4 source to retain all features and functionality.
You can find documentation here, though I’d suggest reading the context around it too:
Do bear in mind that this is an open source project, developed primarily by volunteers and available free of charge. While it is unfortunate that you are working with professional constraints and requirements that put you in a bind they are yours to solve.
@mlvandijk That SO thread is me. 😃
And ofcourse, you too @kathyrollo - feel free to add clarification yourself, or let us know what could be improved 😉
@kathyrollo We just added some info on Type Registry to the docs; you can find it in Cucumber configuration. (@grasshopper7 Please feel free to add to it, if anything is still missing)
@mlvandijk Have been attempting to document migration here - https://github.com/grasshopper7/cuke3-migration. Its a work in progress and kind of covered ParameterType till now. Hopefully finish up DataTableType soon. Was hoping to create an article out of it and post it online. If you like the end product, happy to merge it into existing documentation.
Excellent. It was one of those problems I hoped some one else would solve.
I am going to assume you’ve found what you’ve needed. If not, or if anybody else searches github for this specific problem:
The release announcement for cucumber-jvm 3.0.0 includes some basic instructions on how to use the datatables. It also contains a brief explanation on removal of xstream which underpinned the automatic conversions.