I'm not able to understand the dynamic data ta

2019-07-17 02:15发布

问题:

Anybody know how to use the csv file to create a dynamic data tables.

I'm trying to use the Code defined in the documentation but it's not working for me.

回答1:

The read function accepts csv files and creates an array of json objects from the csv. Header row is always expected and the header is used to create the name of the object members.

Suppose you have a csv like this:

[data.csv]:

name,likes
Cucuma,1
Canyon,2
Stevens,3

Then the following test is green

  Scenario: Read CSV file and convert that to json
    Given json dataFromCsv = read('data.csv')
    Then match dataFromCsv ==
    """
    [
      {name : "Cucuma", likes : '1'}
      {name : "Canyon", likes : '2'}
      {name : "Stevens", likes : '3'}
    ]
    """

You can find that example here. It's a gradle and groovy based test, but I hope it helps.



标签: karate