Cucumber Java: Map Data Tables to Class Objects

Profile picture for user devraj

There is one easier ways to access your data than DataTable. For instance you can create a Class-Object and have Cucumber map the data in a table to a list of these.

Feature File

#Login with multiple users
  Scenario: Verify Login with multiple users
    When I Logged in with users using class objects
      | UserName                    | Password |
      | | test1234 |
      | mahuja                      |   234567 |
      | ssharma                     |   975454 |   

Step Definition

@When("^I Logged in with users using class objects$")
public void user_enters_testuser_and_Test(List<Credentials>  usercredentials) throws Throwable
    //Write the code to handle Data Table
    for (Credentials credentials : usercredentials)

Class Objects

package stepDefinition;

public class Credentials 
    private String username;
    private String password;

    public String getUsername()
        return username;

    public String getPassword()
        return password;