Cucumber:无法将 DataTable 转换为 List。有一个表格单元格转换器,但表格太宽而无法使用

2023-12-31

特征文件:

Scenario: Login to application
Given I open my application
And I login with following credentials 
| admin | pass1234 |

步骤定义:

@When("^I login with following credentials$")
public void i_login_with_following_credentials(DataTable dt) {
    List<String> list = dt.asList(String.class);
    System.out.println("Username - " + list.get(0));
    System.out.println("Password - " + list.get(1));
}

错误:

io.cucumber.datatable.UndefinedDataTableTypeException: Can't convert DataTable to List<java.lang.String>.
There was a table cell converter but the table was too wide to use it.
Please reduce the table width or register a TableEntryTransformer or TableRowTransformer for java.lang.String.

<cucumber.version>5.4.1</cucumber.version>
<junit.version>4.13</junit.version>

您能给建议吗?具体应该添加什么?谢谢。


您正在尝试将数据表转换为字符串列表。因为列表是垂直的并且因为String可以恰好占用一个单元格 Cucumber 期望您有一张只有一列的表格。

| admin    |
| pass1234 | 

但你也可以转置数据表:

List<String> list = dt.transpose().asList(String.class)

或者直接访问单元格:

String username = dt.cell(0,0);
String password = dt.cell(0,1);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Cucumber:无法将 DataTable 转换为 List。有一个表格单元格转换器,但表格太宽而无法使用 的相关文章

随机推荐