Using step datatable

Applies to CucumberStudio Cloud, and to Enterprise ver. 3.3 - Last updated on November 17, 2023

As the free text parameter, there is another special parameter that can be used in CucumberStudio: the step datatable.

This kind of parameter can be added from a step by clicking on the menu and selecting Add table parameter to create a step datatable parameter.

Let’s consider the following scenario:

Adding table parameter

Click the image to enlarge it.

We need to provide CucumberStudio the list of existing users in the system. This could be done by using the scenario datatable but it would generate multiple tests and use only one row by test.

We can use a step datatable to fix that problem:

CucumberStudio step datatable

Click the image to enlarge it.

As with the Gherkin syntax, CucumberStudio expects a table formatted with | characters.

The table is set as an action word argument. The test case will look like this:

CucumberStudio test with datatable step

Click the image to enlarge it.

If we have a look at the action word, we can see that it has now a __datatable parameter:

CucumberStudio actionword datatable parameter

Click the image to enlarge it.

As with the free text parameter, it is mandatory to keep the name __datatable, otherwise it will not behave as a table but as a classic parameter.

Automating the datatable

Non-Gherkin frameworks

When exporting the tests with non-Gherkin based test frameworks, the datatable is passed to the action word as a string.

You will have to implement your own way to handle the data, but the code is pretty simple (here is a Ruby-ish treatment):

treated = datatable.split("\n").map do |line|
  line.split("|").map do |cell|
    cell.trim() // trim removes white spaces around the content
Gherkin frameworks

The Gherkin based frameworks (Cucumber, Behave, Behat, Specflow) will handle the datatable and already provide you ways to access rows and cells.

One known issue with the code generation occurs with Specflow and Cucumber/Java. The generated steps_definitions file will be correct (by giving the Table or DataTable type to the datatable parameter) but the corresponding action word will consider the parameter as a string. This needs to be manually corrected while implementing the action word.

Highlight search results