×
☰ See All Chapters

Cucumber Data Tables

  • Sometime we may need to apply same step (Given, When, Then) to multiple set of data. In such case we need to describe data that doesn’t easily fit on a single line of Given, When, or Then. Gherkin allows describing the step in one line and all multiple set of data in a table right underneath a step. 

  • Example 

cucumber-data-tables-0
 
  • The table should starts on the line immediately following the step,  

  • Cells should be separated using the pipe character: |.  

  • Cucumber will strip out the values in each cell, ignoring the surrounding whitespace. So we can format the table for good look by appending whitespaces.  

  • In the previous example, we’ve used a heading for each column in the table. We can use headings down the side as below: 

    Given Employees with roles:

      | name | Manu Manjunatha | Likitha | Advith           |

      | role | Developer       | Tester  | Junior Developer |

  • Using headings is optional, we can ignore using headings 

Given Employees with roles:

      | Manu Manjunatha | Developer        |

      | Likitha         | Tester           |

      | Advith          | Junior Developer |

  • In whichever the format we use data table, with/without headings, same should be implemented in step definition. 


All Chapters
Author