In Cucumber, DataTables are used to pass multiple values or structured data from a feature file to step definitions.
They help:
1. Avoid repeating steps for similar data
2. Pass structured test data (like form fields, user details, etc.)
3. Simplify test maintenance
Syntax in Feature File
A step followed by a table becomes a DataTable:
Use Cases of DataTables
Cucumber lets you work with DataTables in several formats depending on the structure of the table.
1. Single Column (List)
Use this when there is only one column of data
Step Definition:
2. Multiple Rows with Headers (List of Maps)
Use this when there are multiple columns with headers — each row is a separate record.
Step Definition
Use this when you want to access specific rows and columns.
Note: cell(rowIndex, columnIndex) is zero-based, except header row is always row 0.
Supported Data Formats in Java Step Definitions
Table Format |
Java Collection Type |
Single Column |
List<String> |
Multiple Columns, No Headers |
List<List<String>> |
Rows with Headers |
List<Map<String, String>> |
Vertical Headers |
Map<String, String> |
Nested Map |
Map<String, Map<String, String>> |