使用空手道地图在XML和JSON响应之间进行比较时,如果我运行下面的代码,则会得到TypeError: karate.map is not a function
。这与我以前的question.
我尝试搜索类似的问题,但没有发现任何问题。
* def json =
"""
{
"Main": {
"Cd":"ABC",
"descriptionTxt":"Sample Main",
"type":"A",
"codeType":"P",
"dt":"2018-10-15T00:00:00-05:00",
"validity":"3",
"segment":"Personal"
},
"testList":[
{
"code":"123",
"descriptionTxt":"My Description",
"categoryCd":"DUDU"
},
{
"code":"675",
"descriptionTxt":"His Description"
},
{
"code":"345",
"descriptionTxt":"Your Description",
"categoryCd":"BH"
}]
}
"""
* def xml =
"""
<ns4:root xmlns:ns4="http://foo.com" xmlns:ns5="http://bar.com">
<ns4:Test>
<ns5:code>123</ns5:code>
<ns5:description>My Description</ns5:description>
<ns5:categoryCode>DUDU</ns5:categoryCode>
<ns5:unwanted>Unwanted XML Parameter</ns5:unwanted>
</ns4:Test>
<ns4:Test>
<ns5:code>345</ns5:code>
<ns5:description>Your Description</ns5:description>
<ns5:categoryCode>BH</ns5:categoryCode>
</ns4:Test>
<ns4:Test>
<ns5:code>675</ns5:code>
<ns5:description>His Description</ns5:description>
<ns5:unwanted>Unwanted XML Parameter</ns5:unwanted>
</ns4:Test>
</ns4:root>
"""
* def list = /xml/root/Test
* def fun = function(x){ return { code: xpath(x, '/code'), descriptionTxt: xpath(x, '/description'), categoryCd: xpath(x, '/categoryCode') } }
* def temp = karate.map(list, fun)
* print temp
* print json.testList
* match json.testList contains temp
错误响应
Caused by: javax.script.ScriptException: TypeError: karate.map is not a function in <eval> at line number 1
请帮助!
答案 0 :(得分:1)
确定您使用的是空手道的旧版本。您确定使用的是0.8.0吗?
尝试升级。
如果您仍然遇到问题,请执行以下过程:https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue