There was a breaking change (undocumented afaik) that exists when loading files into local scope. I tested this with both YAML and JSON and was able to replicate across both formats.
Scenario: Load the yaml file directly into local scope - works in 0.9.2, doesnt work in 0.9.3
* call read ('constants.yaml')
* match foo == 'bar'
Scenario: Load the yaml file into a variable - works in both versions
* def constants = read('constants.yaml')
* match constants.foo == 'bar'
Run the sample project (attached) and all tests will pass. Change the karate version in the pom file to 0.9.3 and two of the 4 tests will fail.
I'll admit this has me stumped a bit. it was never the intent to have even * call read('foo.json') work, call is designed only for calling a JS function or Karate feature. not JSON or any other "flat file" format.
for 0.9.3 please make this change - using the new karate.set(map) API, I'll not add this to the release notes yet. if you can figure how it used to be working earlier that would help, I'm giving up for now and will take a look later :| long day
# same goes for *.json as well
# in the next version, the "eval" below can be omitted
* eval karate.set(read('constants.yaml'))
* match foo == 'bar'
reopening. this commit actually made read into a Java lambda and NOT a JS function anymore: https://github.com/intuit/karate/commit/f09470fe7c22f391dea0f1f2ff4eb145d7b87f1d
and call has 2 forms, one for a feature file and the other for JS which works like this:
call jsFunctionRef jsFunctionArg
and separated by spaces. so what used to work is this:
* call read ('constants.yaml')
which resolves to:
* call read 'constants.yaml'
proposed fix is to add Java Function<T, R> as a "first-class" type that Karate is aware of. may come in useful in the future.
this has been fixed, so now BOTH the below forms will work, where cat.json is: { "name": "Bob", "age": 5 }
Scenario: call read (global)
* call read 'cat.json'
* match name == 'Bob'
* match age == 5
Scenario: set read (global)
* karate.set(read('cat.json'))
* match name == 'Bob'
* match age == 5
although this was never designed for in the first place, * call read filename has now emerged as a nice short-cut to inject a bunch of variables into the context from a JSON (or YAML) file
released 0.9.4
Most helpful comment
this has been fixed, so now BOTH the below forms will work, where
cat.jsonis:{ "name": "Bob", "age": 5 }although this was never designed for in the first place,
* call read filenamehas now emerged as a nice short-cut to inject a bunch of variables into the context from a JSON (or YAML) file