1
  • match response contains only QA_Schema Basically both response and QA_Schema have same content. Both have a parameter named attributes which has array of key value pairs

The following is the response

  {  "agentID": null,
    "browserData": null,
    "channel": "CABLEDOTCOM",
    "confidenceLevel": "HIGH",
    "creditCustomAttributes": [
        {
            "name": "accountNumber",
            "value": "8009001002003015"
        },
        {
            "name": "alternatePhoneNumber",
            "value": "7098863456"
        },
        {
            "name": "customerType",
            "value": "Residential"
        },
        {
            "name": "ezEnrollCreditNoCredit",
            "value": "NO"
        },
        {
            "name": "houseNumber",
            "value": "34"
        },
        {
            "name": "inboundPhoneNumber",
            "value": "9079963456"
        },
        {
            "name": "installationDate",
            "value": "12-12-2018"
        },
        {
            "name": "installationTimeSlot",
            "value": "11AM"
        },
        {
            "name": "installationType",
            "value": "self"
        },
        {
            "name": "lineOfBusinessOrdered",
            "value": "video,hsd"
        },
        {
            "name": "mrcFromOrder",
            "value": "$23"
        },
        {
            "name": "operatorId",
            "value": "9097"
        },
        {
            "name": "salesId",
            "value": "99998"
        },
        {
            "name": "timezone",
            "value": "EST"
        },
        {
            "name": "workOrderDate",
            "value": "12-12-2018"
        },
        {
            "name": "workOrderNumber",
            "value": "13-00-11-990-2018"
        }
    ],
    "csgLocationID": null,
    "customerDetails": {
        "billingAddress": {
            "addressLine1": "PO BOX 445",
            "addressLine2": "Apt 345",
            "city": "AO",
            "country": "USA",
            "state": "AE",
            "zipCode": "09061"
        },
        "currentAddress": {
            "addressLine1": "PO BOX 445",
            "addressLine2": "Apt 345",
            "city": "AO",
            "country": "USA",
            "state": "AE",
            "zipCode": "09061"
        },
        "dateOfBirth": "1975-01-01",
        "driversLicense": {
        },
        "name": {
            "firstName": "JOHN",
            "lastName": "BREEN",
            "middleName": "WAKEFIELD"
        },
        "shippingAddress": {
            "addressLine1": "PO BOX 445",
            "addressLine2": "Apt 345",
            "city": "AO",
            "country": "USA",
            "state": "AE",
            "zipCode": "09061"
        },
        "socialSecurityNumber": "666436878",
        "telephoneNumber": "7818945369"
    },
    "customerID": null,
    "customerType": "RESIDENTIAL",
    "hitPreference": "HIT_WITH_NARRATIVE",
    "installationType": null,
    "language": null,
    "lineOfBusiness": null,
    "marketID": "1111",
    "matchPreference": "EXACT_ONE",
    "orderID": null,
    "verificationStatus": {
        "bureauResponse": null,
        "failureReasons": [
            {
                "code": "ERROR",
                "message": "Retriable Server Error. Response Code: 503, Response Message: Service Unavailable"
            },
            {
                "code": "R0201",
                "message": "Workflow Complete."
            }
        ],
        "status": "SUCCESS"
    },
    "workOrderNumber": null
}

The following is the QA_Schema

   { "agentID": null,
    "browserData": null,
    "channel": "CABLEDOTCOM",
    "confidenceLevel": "HIGH",
    "creditCustomAttributes": [
        {
            "name": "lineOfBusinessOrdered",
            "value": "video,hsd"
        },
        {
            "name": "timezone",
            "value": "EST"
        },
        {
            "name": "alternatePhoneNumber",
            "value": "7098863456"
        },
        {
            "name": "mrcFromOrder",
            "value": "$23"
        },
        {
            "name": "workOrderDate",
            "value": "12-12-2018"
        },
        {
            "name": "installationDate",
            "value": "12-12-2018"
        },
        {
            "name": "houseNumber",
            "value": "34"
        },
        {
            "name": "accountNumber",
            "value": "8009001002003015"
        },
        {
            "name": "ezEnrollCreditNoCredit",
            "value": "NO"
        },
        {
            "name": "customerType",
            "value": "Residential"
        },
        {
            "name": "installationType",
            "value": "self"
        },
        {
            "name": "salesId",
            "value": "99998"
        },
        {
            "name": "inboundPhoneNumber",
            "value": "9079963456"
        },
        {
            "name": "workOrderNumber",
            "value": "13-00-11-990-2018"
        },
        {
            "name": "installationTimeSlot",
            "value": "11AM"
        },
        {
            "name": "operatorId",
            "value": "9097"
        }
    ],
    "csgLocationID": null,
    "customerDetails": {
        "age": "#ignore",
        "billingAddress": {
            "addressLine1": "PO BOX 445",
            "addressLine2": "Apt 345",
            "city": "AO",
            "country": "USA",
            "state": "AE",
            "zipCode": "09061"
        },
        "currentAddress": {
            "addressLine1": "PO BOX 445",
            "addressLine2": "Apt 345",
            "city": "AO",
            "country": "USA",
            "state": "AE",
            "zipCode": "09061"
        },
        "dateOfBirth": "##string",
        "driversLicense": {
        },
        "name": {
            "firstName": "JOHN",
            "lastName": "BREEN",
            "middleName": "WAKEFIELD"
        },
        "shippingAddress": {
            "addressLine1": "PO BOX 445",
            "addressLine2": "Apt 345",
            "city": "AO",
            "country": "USA",
            "state": "AE",
            "zipCode": "09061"
        },
        "socialSecurityNumber": "#ignore",
        "telephoneNumber": "7818945369"
    },
    "customerID": null,
    "customerType": "RESIDENTIAL",
    "hitPreference": "HIT_WITH_NARRATIVE",
    "installationType": null,
    "language": null,
    "lineOfBusiness": null,
    "marketID": "1111",
    "matchPreference": "EXACT_ONE",
    "orderID": null,
    "verificationStatus": {
        "bureauResponse": null,
        "failureReasons": [
            {
                "code": "ERROR",
                "message": "Retriable Server Error. Response Code: 503, Response Message: Service Unavailable"
            },
            {
                "code": "R0201",
                "message": "Workflow Complete."
            }
        ],
        "status": "SUCCESS"
    },
    "workOrderNumber": null
}

If you compare these 2 manually, both are exactly the same. But only difference is the order. Both are in different order.

So when I do

  • match response contains only QA_Schema

It is not matching. enter image description here

if there is no way, should I sort the array with in alphabetical order and then do the assertion?

2 Answers2

1

@GopalSubramanian - You can do this in two ways:

  1. Using schema validation if you do not care about the values in arrays.
....
* match response.creditCustomAtributes.#[]
## OR is you also want to check the size of arry but do not care about values then 

* match response.creditCustomAttributes.#[10] ## ensures that there are 10 array values

See documentation here - https://github.com/karatelabs/karate#schema-validation

  1. In case you DO want to validate the values in array against an expected payload then use contains any. I see that @PeterThomas has already showed you an example. Here's the documentation - https://github.com/karatelabs/karate#match-contains-any
Dinesh Arora
  • 2,115
  • 3
  • 24
  • 30
0

When you have nesting, always try to do a match on parts of your JSON. How you divide that is up to you.

I have simplified your complex dump into a simple example. But you will get the idea here:

Feature:

  Scenario:
    * def response =
    """
    {
      "channel": "CABLEDOTCOM",
      "creditCustomAttributes": [
        {
            "name": "timezone",
            "value": "EST"
        },
        {
            "name": "lineOfBusinessOrdered",
            "value": "video,hsd"
        }
      ]
    }
    """

    * def expected =
    """
    {
      "channel": "CABLEDOTCOM",
      "creditCustomAttributes": "#array",
    }
    """

    * match response == expected
    * match response.creditCustomAttributes contains only
    """
    [
      {
          "name": "lineOfBusinessOrdered",
          "value": "video,hsd"
      },
      {
          "name": "timezone",
          "value": "EST"
      }
    ]
    """

Please spend some time studying other answers if needed:

https://stackoverflow.com/a/68789345/143475

https://stackoverflow.com/a/65036047/143475

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248
  • I have updated the response and QA_Schema. What to do in this case? @peter – Gopal Subramanian May 31 '22 at 05:43
  • @GopalSubramanian hello there. I refuse to look at a wholesale dump of your data. if you can simplify your example, just 2-3 rows are enough I will consider answering your question. in the meantime, you can wait for someone else to help you – Peter Thomas May 31 '22 at 05:50
  • Hi @peter The "response" and "QA_Schema" that I used has a parameter called "creditCustomAttributes". This parameter will be having the array of key-values (i.e) "name" and "value". And sometimes this "creditCustomAttributes" might be null too. So I'm trying to do the assertion which just matches the "response" and "QA_Schema". This * match response contains only expected ----> This is not going into the inner child of the "creditCustomAttributes" and then match the array of key-values. – Gopal Subramanian May 31 '22 at 10:44
  • @GopalSubramanian just create a simple JSON with 2 or 3 keys max and one of them being an array. I will then give you an answer in 5 minutes. stack overflow has a rule of a minimal example: https://stackoverflow.com/help/minimal-reproducible-example - it is up to you now, I am not reading your comment – Peter Thomas May 31 '22 at 10:48
  • `* def expected = {"bureauResponse":null,"failureReasons":[{"code":"ERROR","message":"Retriable Server Error. Response Code: 503, Response Message: Service Unavailable"},{"code":"R0201","message":"Workflow Complete."}]},"hitPreference":"IGNORE"}` `* def response = {"bureauResponse":null,"failureReasons":[{"code":"R0201","message":"Workflow Complete."},{"code":"ERROR","message":"Retriable Server Error. Response Code: 503, Response Message: Service Unavailable"}]},"hitPreference":"IGNORE"}` `* match response contains only expected` This is not working – Gopal Subramanian May 31 '22 at 13:55
  • @GopalSubramanian please don't use the comments (I can't read it) and edit the question please. anyway for now I'll give you an answer. the next time if you can't make your question simpler and easier to read, you may not get any more answers – Peter Thomas May 31 '22 at 14:24