Karate - How to import json data

我怕爱的太早我们不能终老 提交于 2019-12-02 07:01:53

问题


I want to import some JSON data to my tests.
In order to documentation I should do that like this:

* def data = read('classpath:init/data.json')

I've created my JSON file with this content:

{
    "name": "ehsan"
}

This is my code:

  Background:
    * def data = call read('classpath:init/data.json')

  Scenario:
    * print data

But it prints nothing and says:

16:11:30.898 [main] WARN com.intuit.karate - not a js function or feature file: read('classpath:init/data.json') - [type: JSON, value: com.jayway.jsonpath.internal.JsonContext@7d61eccf]

回答1:


Below code is correct:

* def data = read('classpath:init/data.json')

Only you must remove [call]




回答2:


Yes, read the error message (and the doc) carefully - there is no meaning in 'calling' a JSON file, the moment you read it - you have your re-usable data already. Just do this:

Background:
    * def data = read('classpath:init/data.json')

  Scenario:
    * print data


来源:https://stackoverflow.com/questions/47035817/karate-how-to-import-json-data

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