Multiple Test Data using Data table in Cucumber

June 30, 2018

When we have multiple test data to be passed in a single step of a feature file, one way is to pass multiple parameters and another way is to use Data Tables.

Data Tables is a data structure provided by cucumber. It helps you to get data from feature files to Step Definitions. Its a bridge between feature file and Step Definition to pass values to the parameters.

Data can be passed as a large number of data, as One-Dimensional data, as two-dimensional data and also in formย of key-value pair.

Using Data Table as a List:

Let us consider a scenario: I want to Sign up to Facebook (http://facebook.com) where we have to pass data like Firstname, Surname, Mobile Number, Password, Date Of Birth, Gender.

Feature File:

Step Definition File:

In the above scenario, Data Table is sending the list of data in the one-dimensional form. We received the data in a list of String and passed in order.

Using Data Table in key-value pair:

Let us consider a scenario: I want to login to Facebook (http://facebook.com) with username and password. We will pass username and password as parameters using Data Tables.

Feature File:

Step Definition File:

In the above example, the values are passed as the key-value format. Username – saurabh.d2106@gmail.com, and Password – password. While receiving the data we converted the DataTable data structure into Map using a method called testData.asMap(String.class, String.class). Argument mention the data type.

For any questions, queries or comments feel free to write us at support@qatechhub.com or saurabh@qatechub.com. Happy Learning ๐Ÿ™‚

Saurabh Dhingra

About the Author

Saurabh Dhingra

Follow Saurabh Dhingra:

Leave a Comment: