Cucumber-JVM 3 - io.cucumber.datatable.UndefinedDataTableTypeException(Cucumber-JVM 3 - io.cucumber.datatable.UndefinedDataTableTypeException)
问题描述
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?
UPDATE:
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.
public class Configurer implements TypeRegistryConfigurer {
@Override
public void configureTypeRegistry(TypeRegistry registry) {
registry.defineDataTableType(new DataTableType(Income.class, new TableEntryTransformer<Income>() {
@Override
public Income transform(Map<String, String> entry) {
return new Income(entry.get("name"),entry.get("amount"),entry.get("frequency"));
}
}));
}
@Override
public Locale locale() {
return Locale.ENGLISH;
}
}
UPDATED Imports... Not all are required, keep what is relevant
import cucumber.api.TypeRegistry;
import cucumber.api.TypeRegistryConfigurer;
import io.cucumber.cucumberexpressions.ParameterType;
import io.cucumber.datatable.DataTable;
import io.cucumber.datatable.DataTableType;
import io.cucumber.datatable.TableCellTransformer;
import io.cucumber.datatable.TableEntryTransformer;
import io.cucumber.datatable.TableRowTransformer;
import io.cucumber.datatable.TableTransformer;
这篇关于Cucumber-JVM 3 - io.cucumber.datatable.UndefinedDataTableTypeException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Cucumber-JVM 3 - io.cucumber.datatable.UndefinedDataTableTypeException
基础教程推荐
- Java 中保存最后 N 个元素的大小受限队列 2022-01-01
- 如何在不安装整个 WTP 包的情况下将 Tomcat 8 添加到 Eclipse Kepler 2022-01-01
- 如何使用 Eclipse 检查调试符号状态? 2022-01-01
- 如何对 HashSet 进行排序? 2022-01-01
- 如何使用 Stream 在集合中拆分奇数和偶数以及两者的总和 2022-01-01
- 由于对所需库 rt.jar 的限制,对类的访问限制? 2022-01-01
- 首次使用 Hadoop,MapReduce Job 不运行 Reduce Phase 2022-01-01
- 在螺旋中写一个字符串 2022-01-01
- 如何强制对超级方法进行多态调用? 2022-01-01
- Spring Boot Freemarker从2.2.0升级失败 2022-01-01