3

While comparing between XML and JSON responses using karate map, If I run below code i get, TypeError: karate.map is not a function. This is related to my previous question.

I tried searching for similar issues but not found any.

* 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

Error Response

Caused by: javax.script.ScriptException: TypeError: karate.map is not a function in <eval> at line number 1

Please help!

Nitheesh hunsur
  • 151
  • 2
  • 11

1 Answers1

1

Pretty sure you are on an old version of Karate. Are you sure you are using 0.8.0 ?

Try upgrading.

If you still are stuck, please follow this process: https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue

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