Feature file:
Scenario: Login to application
Given I open my application
And I login with following credentials
| admin | pass1234 |
StepDefs:
@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));
}
The error:
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>
Could you please advice? What exactly should be added? Thank you.
You're trying to turn a data table into a list of strings. Because lists are vertical and because String
can take up exactly one cell Cucumber expects that you have a table that has exactly one column.
| admin |
| pass1234 |
But you can also transpose the data table:
List<String> list = dt.transpose().asList(String.class)
Or simply access the cells directly:
String username = dt.cell(0,0);
String password = dt.cell(0,1);
Use asLists insted of asList to work
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With