简体   繁体   English

空手道-如何导入JSON数据

[英]Karate - How to import json data

I want to import some JSON data to my tests. 我想将一些JSON数据导入到我的测试中。
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: 我已经使用以下内容创建了JSON文件:

{
    "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]

Below code is correct: 下面的代码是正确的:

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

Only you must remove [call] 只有您必须删除[通话]

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. 是的,请仔细阅读错误消息(和文档)- read JSON时“调用” JSON文件没有任何意义-您已经拥有可重复使用的数据。 Just do this: 只要这样做:

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

  Scenario:
    * print data

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM