当我尝试断言整个阵列的整个json时,只有包含是不起作用的

发布于 2025-02-02 17:26:37 字数 7324 浏览 4 评论 0 原文

  • 匹配响应仅包含qa_schema 基本上响应 QA_Schema 具有相同的内容。两者都有一个名为属性的参数具有关键值对的数组,

以下是响应

  {  "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
}

以下是 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
}

如果您手动比较这2个,两者都是完全一样的。但是唯一的区别是顺序。两者都处于不同的顺序。

因此,当我确实

  • 匹配响应仅包含QA_Schema

时,它与不匹配。

如果没有办法,我应该按字母顺序排序数组,然后做断言?

  • 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

风柔一江水 2025-02-09 17:26:37

@gopalsubramanian-您可以通过两种方式执行此操作:

  1. 如果您不关心数组中的值,请使用架构验证。
....
* 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

请参阅此处的文档 -

  1. 如果您 do 想要验证数组中的值对预期有效载荷,则使用任何内容。我看到@peterthomas已经向您展示了一个例子。这是文档 -

@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
愛上了 2025-02-09 17:26:37

当您筑巢时,请始终尝试在JSON的一部分上进行匹配。您如何分裂您的决定。

我将您的复杂转储简化为一个简单的示例。但是您会在这里得到这个想法:

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"
      }
    ]
    """

如果需要,请花一些时间研究其他答案:

143475

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文