Skip to main content

Cucumber Java: Map Data Tables to Class Objects

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;

cucumber with java course on Udemy

Submitted by tgoswami on August 30, 2020

Tarun has 11+ years of experience in Quality Assurance in different domains like Banking, E-commerce, Health and Education.


At ProgramsBuzz, you can learn, share and grow with millions of techie around the world from different domain like Data Science, Software Development, QA and Digital Marketing. You can ask doubt and get the answer for your queries from our experts.