@DataTable and @ForEach
Consider the following example step containing a data table.
Feature step with data table
When the following items are added
| Item |
| Get the milk |
| Walk the dog |
This example defines a single column table containing a header followed by two entries.
A StepDef could be defined to process each row of data in the table as follows:
StepDef for processing data table
Scenario: the following items are added
Given the todo field can be located by class "new-todo"
And my todo list can be located by css ".todo-list"
When I enter Item in the todo field
Then my todo list should contain Item
StepDef will be executed for each row of data in the table (2 times in this example)
@ForEach annotations work together to process each record in the data table. When the feature step is evaluated, Gwen will call the StepDef for each record in the table and bind each field value to its declared name in the header record. The last two steps in this example will enter each
Item into a
todo field and check that it was added to
my todo list.
The following attributes are also implicitly available to data table StepDefs: