Karate 空手道:当使用三元(?:)运算符并将值分配给用def关键字声明的变量时,xml被类型转换为json

Karate 空手道:当使用三元(?:)运算符并将值分配给用def关键字声明的变量时,xml被类型转换为json,karate,Karate,我有两个文件,一个是json,一个是xml。我想根据isJson标志打印json或xml文件内容。但是我看到,当isJson==false从下面的程序返回json内容时 Scenario: ternary operator over different type files * def isJson = false * json jsonFile = {name : 'user'} * xml xmlFile = <name>user</name> * def paylo

我有两个文件,一个是json,一个是xml。我想根据
isJson
标志打印json或xml文件内容。但是我看到,当
isJson==false
从下面的程序返回json内容时

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

空手道确实尝试自动检测,但有时无法打印-但在幕后它是XML,您可以正常发送/使用它。我还强烈建议您不要编写此类动态测试。请仔细阅读:

所以你可能不得不接受这个,或者请贡献代码。请注意,如果使用
karate.prettyXml()
,可以看到变量以XML形式打印(如果是)。下一个1.0版本可能会改进这一点,但不能保证

INFO  com.intuit.karate - [print] payload ---> {
 "name": "user"
}