Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cucumber: Can't convert DataTable to List<java.lang.String>. There was a table cell converter but the table was too wide to use it

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.

like image 906
Bob Bolden Avatar asked Mar 03 '23 17:03

Bob Bolden


2 Answers

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);
like image 101
M.P. Korstanje Avatar answered Mar 05 '23 06:03

M.P. Korstanje


Use asLists insted of asList to work

like image 36
Manju Avatar answered Mar 05 '23 06:03

Manju