We might need to supply multiple data instead of hardcoded value passed in steps from feature files, this happens most of the time while working with your project
This can be done using DataTable class available in Cucumber, basically DataTables are of type List<List<String>>
Table in the scenario looks something like this
Here is the complete videos of the above discussion
Working with DataTable using DataTable.raw()
Working with DataTable using custom class
Thanks for reading the post and watching the video!!!
Please leave your comments and let me know if there is anything I should update in this post.
Thanks,
Karthik KK
Post Author:
Karthik kk
9 Replies to “Working with multiple data using DataTable in Cucumber for Java”
Hi karthik,
Thanks for sharing the video. Your sessions are too good and it’s very easy to understand.
Regarding the java properties why it didn’t worked is, in java the properties always should start with small letter. Java uses reflection technology to set/get the values.
Your step is two parts And part term is part number is “” with quantity
|term |part number |quantity |
|24 |D1P3NLL |5 |
1. And part term is part number is “” with quantity
It has a string with double quotes, which cucumber transformer will automatically transform to string.
2. |term |part number |quantity |
|24 |D1P3NLL |5 |
Table is always cucumber Table class
Thats the reason you are seeing two parameters in the Step definition.
Thanks for post. I have one question. Is it possible to read datatable vertically? I have a step with huge no of parameters. and data is varying every time for each test case.
Hi frnds,
From example in feature file ,I have to pass different data into different fields but while executing two different data is passing to one field.any one can help
Hi Kartik,
In one of my scenario five different data examples are there. So every example is considered as a separate test. Due to which the total test number is 5. So cucumber reports are showing 5 test cases executed, but actually it is one only.
So any way how we can handle this.
Hi karthik,
Thanks for sharing the video. Your sessions are too good and it’s very easy to understand.
Regarding the java properties why it didn’t worked is, in java the properties always should start with small letter. Java uses reflection technology to set/get the values.
Thanks Jagan, I realized it very late, but thanks for your comments.
I add the following field in feature file,
And part term is part number is “” with quantity
|term |part number |quantity |
|24 |D1P3NLL |5 |
why the generated java code is like this:
public void SpecifyPartTermAndQuantity(String arg1,DataTable arg2)
I print arg1 and arg2, it shows as this:
arg1 is part number, arg2 is the who table I filled in feature file.
I don’t understand why….thanks
Your step is two parts
And part term is part number is “” with quantity
|term |part number |quantity |
|24 |D1P3NLL |5 |
1.
And part term is part number is “” with quantity
It has a string with double quotes, which cucumber transformer will automatically transform to string.
2.
|term |part number |quantity |
|24 |D1P3NLL |5 |
Table is always cucumber
Table
classThats the reason you are seeing two parameters in the Step definition.
Thanks,
Karthik KK
Hi Karthik,
Thanks for post. I have one question. Is it possible to read datatable vertically? I have a step with huge no of parameters. and data is varying every time for each test case.
yes its possible. Use map instead of above mentioned process. its very easy with key value pairs
Hi frnds,
From example in feature file ,I have to pass different data into different fields but while executing two different data is passing to one field.any one can help
| subjectOptions | telephone |
| Clinical inquiry | 3215469871 |
| ClinCheck review | 6549873212 |
in a particular field ,data is entering as “3215469871 Clinical” its combining data from telephone +partial data from subjectOptions
Hi Kartik,
In one of my scenario five different data examples are there. So every example is considered as a separate test. Due to which the total test number is 5. So cucumber reports are showing 5 test cases executed, but actually it is one only.
So any way how we can handle this.
I don’t want to give values in Examples instead want to give values in Excel how it can be done can you give an example?