Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert a HashMap to cucumber dataTable?

I want to know if there is any way to convert a HashMap to a DataTable in java Cucumber. I tried doing some googling and saw that the reverse is possible. Any idea on how to implement this?

Thanks in advance.

like image 342
Srikkanth Govindaraajan Avatar asked Oct 17 '22 19:10

Srikkanth Govindaraajan


1 Answers

Considering that

  1. All the data is kept in the map as Strings and
  2. You want a single row in your data table, wherein headers would be keys and row items would be values from the input hashmap. If the conversion would have been other way around, then you would have a list of Maps as Data table would have multiple rows (values for different maps) against the columns (keys).

You could try:

List<List<String>> data = Arrays.asList(new ArrayList<String>(map.keySet()), new ArrayList<String>(map.values())); 
DataTable dataTable = DataTable.create(data);

P.S. I have not tested the syntax.

like image 76
gargkshitiz Avatar answered Oct 21 '22 00:10

gargkshitiz