Tutorial 8 DataTable AsLists in Cucumber.docx
Tutorial 8 DataTable AsLists in Cucumber.docx
To make this simpler, we will use the DataTable feature in cucumber and write as follows.
We write the pipe separated user data and notice that the feature file is more readable
now. The file contains the data of 3 users.
So let us do that
So when the 2nd step @When will be executed, the multiple data sets that you have
given in the feature file will be coming to this particular dataTable
Next, let us write simple SOPs for first and third step
Now, what kind of list you want to get? We want to get ‘String’ type of list, because the
dataset in the feature file is in string format. So we will simply write String.class
Now, as you can see below, this asLists() method returns “List of List of object”. Again,
this list will again be of type ‘String’
So we can say
So we have
Next, we will create a ‘for’ loop so that we can traverse this particular userList.
So, we want to traverse through a ‘List of string’ viz List<String>
It means, print each and every list. So in the first iteration, we will be getting the first list
viz first set of data
In the second iteration, we will get
And so on…
Save the step definition file.
Let us now re-run our feature file
See the console. When the user is on registration page, we are entering the 3 data set of
values
So like this way, you can use the concept of datatable in cucumber. The datatable can be
applied to any type of step Given/When/Then etc..
Let us create a RunnerTest file and run it as Junit test
See the console o/p below. We get exactly the same thing
Reference
You can further refer www.baeldung.com/cucumber-data-tables