Working with multiple data using DataTable in Cucumber for Java

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

4 comments

  1. Jagan says:

    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. Lluvia says:

    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

    • Karthik kk says:

      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,
      Karthik KK

Leave a Reply

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