Site Loader
Auckland, New Zealand
In our last post we discussed getting started with cucumber for Java, in this post we will discuss working with multiple data using DataTable in Cucumber for Java. We have already discussed about working with multiple data in Specflow of C#, which has Table class, but here in Cucumber for Java they have class named DataTable.

Working with multiple data in Cucumber

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”

  1. 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.

  2. 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

    1. 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.

      Karthik KK

  3. 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.

  4. 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

  5. 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.

  6. 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?

Leave a Reply

Your email address will not be published. Required fields are marked *