Q:

Karate - Validate json responses stored in different files

I need to validate 2 json responses which are stored in two different files. I am reading them and comparing. But i get an error reason: all key-values did not match and there're few elements not being matched. This problem occurs only when i store the json in a file and read in my feature file.
Json File 1: Test.json

{
   "webServiceDetail":{
      "feature":{
         "featureCd":"ABCD",
         "imaginaryInd":"100.0",
         "extraInd1":"someRandomValue1"
      },
      "includefeatureList":[
         {
            "featureCd":"PQRS",
            "featureName":"Checking SecondAddOn Service",
            "extraInd1":"someRandomValue1",
            "extraInd2":"someRandomValue1"
         },
         {
            "featureCd":"XYZ",
            "featureName":"Checking AddOn Service",
            "imaginaryInd":"50.0"
         }
      ]
   }
}

Json File 2: Test1.json

{
   "webServiceSummary":{
      "service":{
         "serviceCd":"ABCD"
      },
      "includeServicesList":[
         {
            "serviceCd":"XYZ",
            "serviceDescription": "Checking AddOn Service"
         },
         {
            "serviceCd":"PQRS",
            "serviceDescription":"Checking SecondAddOn Service"
         }
      ]
   }
}

Now, I am using below code to match two json files.
* def Test = read('classpath:PP1/data/Test.json')
* def Test1 = read('classpath:PP1/data/Test1.json')

* def feature = Test.webServiceDetail.feature
* set expected.webServiceSummary.service
| path               | value                |
| serviceCd          | feature.featureCd    |

* def mapper = function(x){ return { serviceCd: x.featureCd, serviceDescription: x.featureName} }
* def expectedList = karate.map(Test.webServiceDetail.includefeatureList, mapper)
* set expected.webServiceSummary.includeServicesList = expectedList
* print expected
* print Test1
* match Test1 == expected

Below is the error response.

com.intuit.karate.exception.KarateException: Test.feature:35 - path: $, actual: {webServiceSummary={service={serviceCd=ABCD}, includeServicesList=[{"serviceCd":"XYZ","serviceDescription":"Checking AddOn Service"},{"serviceCd":"PQRS","serviceDescription":"Checking SecondAddOn Service"}]}}, expected: {webServiceSummary={service={serviceCd=ABCD}, includeServicesList=[[object Object], [object Object]]}}, reason: all key-values did not match

A:

You are close, but the order of includeServicesList is not matching. Make this one change:
* set expected.webServiceSummary.includeServicesList = '#(^^expectedList)'

