SoapUI:计数JSON数组响应中返回的节点 [英] SoapUI: Count Nodes Returned in JSON Array Response

查看:152
本文介绍了SoapUI:计数JSON数组响应中返回的节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用SoapUI学到了很多东西,但是,我只是停留在这一件事上。我返回了以下有效负载:

  [
{
@c: .CreditPaymentInfo ,
supplementalInfo:空,
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:空
}
]

我想要以计算返回的节点数...因此,在这种情况下,我希望每当我在SoapUI中运行此测试步骤时都将返回2个节点。



我试图使用JsonPath Count断言来完成此操作,但是,我只是看不到正确设置其格式。



任何帮助将不胜感激!

解决方案

我没有使用过JsonPath,但是您可以通过XPath来做到这一点……它也适用于所有旧版本。 / p>

内部SoapUI将所有内容都表示为XML。因此,您可以使用XPath断言来检查以下内容:

  $ {#ResponseAsXml#count(// *:id)} 

,并确保返回为

  2 


I've learned so much using SoapUI, but, I'm just stuck on this one thing. I have the following payload returned:

[
      {
      "@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
   }
]

I would like to count how many nodes are returned... so, in this case, I would expect that 2 nodes be returned whenever I run this test step in SoapUI.

I was attempting to get this done using the JsonPath Count assertion, but, I just can't see to format it correctly.

Any help would be greatly appreciated!

解决方案

I have not used JsonPath, but you can do this with XPath ... which works for all older versions too.

Internally SoapUI represents everything as XML. So you could use XPath assertion to check for:

${#ResponseAsXml#count(//*:id)}

and make sure it comes back as

2

这篇关于SoapUI:计数JSON数组响应中返回的节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆