I'm not able to understand the dynamic data tables scenarios in Karate

狂风中的少年 提交于 2020-01-04 07:34:52

问题


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.



来源:https://stackoverflow.com/questions/55743401/im-not-able-to-understand-the-dynamic-data-tables-scenarios-in-karate

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!