4

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]
ehsan shirzadi
  • 4,709
  • 16
  • 69
  • 112

2 Answers2

10

Below code is correct:

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

Only you must remove [call]

Homayoun Behzadian
  • 1,053
  • 9
  • 26
5

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
Peter Thomas
  • 54,465
  • 21
  • 84
  • 248