← Back to libraryQuestion 256 of 468
šŸ„’Cucumber / BDDIntermediate

DataTables

šŸ“Œ Definition:

A DataTable passes tabular data to a single step, letting one step receive multiple values or rows (e.g. a list of products, a set of form fields) without cramming them into the sentence.

šŸ“– Detailed Explanation:

Under a step you add a pipe-delimited table; the step definition receives it as a DataTable, which you convert to a List<Map<String,String>>, List<List<String>>, or a List of POJOs via a @DataTableType. This is ideal for form filling (field/value pairs) or verifying a collection (expected rows in a grid). DataTables differ from Scenario Outline: a DataTable feeds ONE step within a single scenario run, while an Outline runs the whole scenario once per row. Use DataTables for structured input/expected data to a step; use Outline to repeat a scenario across cases.

šŸ”‘ Key Points:
  • Passes tabular data to ONE step (rows/columns)
  • Converted to List<Map>, List<List>, or List<POJO>
  • Great for form fields or verifying a collection
  • Differs from Scenario Outline (which repeats the whole scenario)
šŸŒ Real-World Example:

When user registers with:\n | field | value |\n | name | QA |\n | email | qa@test.com |\n— the step receives these field/value pairs and fills the form, keeping the scenario clean.

šŸŽÆ Scenario-Based Interview Question:

What's the difference between a DataTable and a Scenario Outline's Examples table?