1

I am having two files one is json and one is xml. I want to print json or xml file content on the basis of the isJson flag. But I am seeing that when the isJson == false its returning the json content from the below program.

Scenario: ternary operator over different type files
* def isJson = false
* json jsonFile = {name : 'user'}
* xml xmlFile = <name>user</name>
* def payload = isJson == true ? jsonFile : xmlFile
* print 'payload --->',payload

console output :

INFO  com.intuit.karate - [print] payload ---> {
 "name": "user"
}
Dilip Meghwal
  • 632
  • 6
  • 15

1 Answers1

1

Karate does try to auto-detect, but can fail sometime to print - but behind the scenes it is XML and you can send / use it normally. I also strongly recommend that you don't write these kinds of dynamic tests. Please read this carefully: https://stackoverflow.com/a/54126724/143475

So you may have to live with this, or please contribute code. Note that if you use karate.prettyXml() you can see the variable printed as XML if it is. The next 1.0 version may improve this, but no guarantees.

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248