黄瓜-JVM 3 - io.cucumber.datatable.UndefinedDataTableTypeException [英] Cucumber-JVM 3 - io.cucumber.datatable.UndefinedDataTableTypeException
问题描述
我在 pom.xml
中从 Cucumber-JVM 2.4.0 更新到 3.0.2,DataTables 开始抛出这个异常:
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:无法转换要列出的数据表
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
我将所有导入更改为
import io.cucumber.datatable.DataTable;
我执行了 mvn clean install
并且编译成功,但更新后涉及 DataTables 的步骤不再有效.
I did an mvn clean install
and compilation was successful but steps involving DataTables no longer work after the update.
当前代码:
// 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
}
在 Cucumber-JVM v3.x.x 中是否有使用 DataTables 的新方法?
Is there a new way to use the DataTables in Cucumber-JVM v3.x.x?
更新:
推荐答案
它已经过彻底改造.XStream 已被移除,因此之前的代码将无法工作.
It has been totally revamped. XStream has been removed , so earlier code will not work.
您需要为数据表和参数转换添加逻辑.参考这些 - https://github.com/cucumber/cucumber/tree/master/datatable 和 https://github.com/cucumber/cucumber/tree/主/黄瓜表达式.将下面的类代码放在粘合选项中定义的包中.
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;
这篇关于黄瓜-JVM 3 - io.cucumber.datatable.UndefinedDataTableTypeException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!