SoapUI:计数 JSON 数组响应中返回的节点
SoapUI: Count Nodes Returned in JSON Array Response
我使用 SoapUI 学到了很多东西,但是,我只是坚持这一点。我返回了以下有效负载:
[
{
"@c": ".CreditPaymentInfo",
"supplementalInfo": null,
"date": "06/30/2015 17:03:50",
"posTxCode": "107535",
"amt": 2.56,
"transactionId": 235087,
"id": 232163,
"cardType": "CREDIT",
"cardHolderName": "SMITH2/JOE",
"expMonthYear": "0119",
"lastFourDigits": "4444",
"approvalCode": "315PNI",
"creditTransactionNumber": "A71A7DB6C2F4"
},
{
"@c": ".CreditPaymentInfo",
"supplementalInfo": null,
"date": "07/01/2015 15:53:29",
"posTxCode": "2097158",
"amt": 58.04,
"transactionId": 235099,
"id": 232176,
"cardType": "CREDIT",
"cardHolderName": "SMITH2/JOE",
"expMonthYear": "0119",
"lastFourDigits": "4444",
"approvalCode": "",
"creditTransactionNumber": null
}
]
我想计算返回了多少个节点...因此,在这种情况下,每当我 运行 在 SoapUI 中执行此测试步骤时,我希望返回 2 个节点。
我试图使用 JsonPath Count 断言来完成这项工作,但是,我无法正确格式化它。
如有任何帮助,我们将不胜感激!
我没有使用过 JsonPath,但您可以使用 XPath 来实现...它也适用于所有旧版本。
SoapUI 在内部将所有内容表示为 XML。所以您可以使用 XPath 断言来检查:
${#ResponseAsXml#count(//*:id)}
并确保它返回为
2
这是 JSON 格式。只需使用 JsonPath 计数。在顶部使用 $,在底部使用 2。
$[index].your.path.here
因此
$[0].date would return "06/30/2015 17:03:50"
和
$[1].date would return "07/01/2015 15:53:29"
使用以下之一(假设我的顶级对象是一个数组)'JsonPath count' 成功计数:
$
$.
$[*]
如果您需要更具体地计算您正在计数的对象,您可以仅依赖第三种语法,指定冗余字段之一。以下其中一项对我有用:
$[*].fieldName
$[*].['fieldName']
在您的情况下 return 2 应符合以下条件之一:
$[*].@c
$[*].['@c']
$[*].id
$[*].['id']
以此类推
我使用 SoapUI 学到了很多东西,但是,我只是坚持这一点。我返回了以下有效负载:
[
{
"@c": ".CreditPaymentInfo",
"supplementalInfo": null,
"date": "06/30/2015 17:03:50",
"posTxCode": "107535",
"amt": 2.56,
"transactionId": 235087,
"id": 232163,
"cardType": "CREDIT",
"cardHolderName": "SMITH2/JOE",
"expMonthYear": "0119",
"lastFourDigits": "4444",
"approvalCode": "315PNI",
"creditTransactionNumber": "A71A7DB6C2F4"
},
{
"@c": ".CreditPaymentInfo",
"supplementalInfo": null,
"date": "07/01/2015 15:53:29",
"posTxCode": "2097158",
"amt": 58.04,
"transactionId": 235099,
"id": 232176,
"cardType": "CREDIT",
"cardHolderName": "SMITH2/JOE",
"expMonthYear": "0119",
"lastFourDigits": "4444",
"approvalCode": "",
"creditTransactionNumber": null
}
]
我想计算返回了多少个节点...因此,在这种情况下,每当我 运行 在 SoapUI 中执行此测试步骤时,我希望返回 2 个节点。
我试图使用 JsonPath Count 断言来完成这项工作,但是,我无法正确格式化它。
如有任何帮助,我们将不胜感激!
我没有使用过 JsonPath,但您可以使用 XPath 来实现...它也适用于所有旧版本。
SoapUI 在内部将所有内容表示为 XML。所以您可以使用 XPath 断言来检查:
${#ResponseAsXml#count(//*:id)}
并确保它返回为
2
这是 JSON 格式。只需使用 JsonPath 计数。在顶部使用 $,在底部使用 2。
$[index].your.path.here
因此
$[0].date would return "06/30/2015 17:03:50"
和
$[1].date would return "07/01/2015 15:53:29"
使用以下之一(假设我的顶级对象是一个数组)'JsonPath count' 成功计数:
$
$.
$[*]
如果您需要更具体地计算您正在计数的对象,您可以仅依赖第三种语法,指定冗余字段之一。以下其中一项对我有用:
$[*].fieldName
$[*].['fieldName']
在您的情况下 return 2 应符合以下条件之一:
$[*].@c
$[*].['@c']
$[*].id
$[*].['id']
以此类推