1

I am comparing the JSON responses for two services, they should return similar responses, but sometimes some of the test cases fail becuase some attributes are different. we want to group by the failed cases and see what elements are different. for examplegrop by indxes is the index in aary id differnet or account Number if they are not matching...

I wrote this code to figure it out but code does not work. Certainly! Here's an example of how you can write the code in the Karate framework to group the mismatched elements based on the serialNumber attribute:

Feature: Compare Cache getEquipment and SPC getEquipment Service Responses for Multiple Accounts

  Background:
    # configure truststore


    # Group the mismatched elements based on serialNumber
    * def mismatchedElements = {}

    * def cacheItems = cacheResponse.response
    * def spcItems = spcResponse.response

    * def cacheSize = cacheItems.length
    * def spcSize = spcItems.length
    * def loopSize = Math.min(cacheSize, spcSize)

    * karate.repeat(loopSize, function(index) {
        * def cacheItem = cacheItems[index]
        * def spcItem = spcItems[index]

        # Compare serialNumber attribute
        * if (cacheItem.serialNumber != spcItem.serialNumber) {
            * def mismatchedKey = cacheItem.serialNumber
            * def mismatchedValue = { cacheResponse: cacheItem, spcResponse: spcItem }
            * karate.set(mismatchedElements, mismatchedKey, mismatchedValue)
        }
    })

    # Log the grouped mismatched elements
    * print 'Grouped Mismatched Elements:', mismatchedElements
  • sorry I'm completely lost, and I pass on this question. perhaps if you give a **simple** example of the 2 jsons that might help others help you – Peter Thomas Jul 05 '23 at 18:45
  • also before trying any thing else, first read this: https://stackoverflow.com/a/53120851/143475 – Peter Thomas Jul 05 '23 at 19:02

0 Answers0