Data Tables

Data Tables are a standard practice to pass data in a tabular format. Tabular formats have an advantage in that it can represent large data sets in a comprehensible manner and there are many viewers and editors that can read tabular format. Of course when we come to programming, a table can be something in memory as a data structure and the how we might create the data structure and how we represent that data structure to different sets of audience is a nice topic to discuss in itself. Suffice to say here that we can represent a tabular data structure in multiple file formats like excel, csv, tab separated, xml, json, yml and pretty much any customized format.

Pre-requisites:

  1. You have completed the section “Set up Env” and have your environment ready with JDK, maven and IntelliJ
  2. You have read and understood HTML DOM
  3. You were able to comprehend “Test Data” post
  4. You downloaded the project code base for class7 under – https://github.com/machzqcq/CucumberJVMExamples and imported into Eclipse and the structure should look as below
class7_eclipse_project_structure
If imported into IntelliJ, the structure looks as below
class7_project_structure

Use Case:

We fill forms on websites and hit submit and this is one of the most common functionality that we come across. While Automation, we might have to test the form with multiple sets of data. For example the below web form has lots of fields in it and our requirement might be to test the data with different data sets.

SimpleForm

Scenario Outline:

Cucumber gives us a construct called Scenario Outline to be able to parameterize the data table and also loop through each data set repeating the operations on the form submission. The other keyword to be used is Examples: Cucumber picks the data parameter values from the Examples: and loops through the data table.

 

In the below Cucumber example, the form gets filled with each row in the data table and the operations are repeated for each row. Didn’t that reduce our work of specifying the operations for each data set in a separate scenario?

Entire Cucumber Scenario:

Step Definitions