如何在Jmeter中对JSON响应应用条件



响应如下,

我必须提取所有"deviceResponseStatus.id",其中status="PENDING"如何在Jmeter中使用JSON Path或REGEX实现它?

{
  "apiResponseStatus": "SUCCESS",
  "deviceResponseList": [
    {
      "apiResponseStatus": "SUCCESS",
      "id": 23,
      "ownership": "CORPORATE",
      "deviceName": "Demimbu",
      "deviceType": "MOBILE",
      "osType": "ANDROID",
      "inTotalStorage": 0,
      "inAvailableStorage": 0,
      "exTotalStorage": 0,
      "exAvailableStorage": 0,
      "osVersion": "4.2",
      "buildVersion": "1.01.08",
      "status": "PENDING",
      "isDeleted": false,
      "policyIdNames": {
        "id": 3,
        "name": "Test Policy 3"
      },
      "deviceGroupIdNames": {
        "id": 1,
        "name": "Default Group"
      },
      "userIdName": {
        "id": 1,
        "name": "Randy Lewis"
      },
      "lastConnected": 1423810405000,
      "createdByIdName": {
        "id": 1,
        "name": "Randy Lewis"
      },
      "locked": false,
      "traceOn": false,
      "userEmail": "mdm.user1@gmail.com",
      "enrollmentDate": 1423790255000,
      "simNumbers": [
        "1236547896"
      ],
      "imeiCodes": [],
      "mobileNumbers": [
        "4558585858858"
      ],
      "createDate": 1421927250000,
      "lastModified": 1423810406000,
      "rooted": false,
      "roaming": false,
      "compliant": false
    },
    {
      "apiResponseStatus": "SUCCESS",
      "id": 24,
      "ownership": "CORPORATE",
      "deviceName": "Photobean",
      "deviceType": "MOBILE",
      "osType": "ANDROID",
      "inTotalStorage": 20941258752,
      "inAvailableStorage": 8024924160,
      "exTotalStorage": 0,
      "exAvailableStorage": 0,
      "bluetoothMacAddress": "8C:3A:E3:BE:C2:04",
      "wirelessMacAddress": "8c:3a:e3:51:bb:e3",
      "model": "LG-D686",
      "osVersion": "4.4.2",
      "buildVersion": "1.01.09",
      "status": "PENDING",
      "isDeleted": false,
      "policyIdNames": {
        "id": 3,
        "name": "Test Policy 3"
      },
      "deviceGroupIdNames": {
        "id": 1,
        "name": "Default Group"
      },
      "userIdName": {
        "id": 1,
        "name": "Randy Lewis"
      },
      "make": "LGE",
      "lastConnected": 1423648831000,
      "createdByIdName": {
        "id": 1,
        "name": "Randy Lewis"
      },
      "locked": false,
      "traceOn": false,
      "userEmail": "mdm.user1@gmail.com",
      "enrollmentDate": 1423628675000,
      "simNumbers": [
        "404909008623970"
      ],
      "imeiCodes": [
        "359004053152889",
        "359004053152871"
      ],
      "mobileNumbers": [
        "638847339387"
      ],
      "createDate": 1422435029000,
      "lastModified": 1423648831000,
      "rooted": true,
      "roaming": false,
      "compliant": false
    },
    {
      "apiResponseStatus": "SUCCESS",
      "id": 25,
      "ownership": "CORPORATE",
      "deviceName": "Livetube",
      "deviceType": "MOBILE",
      "osType": "ANDROID",
      "inTotalStorage": 0,
      "inAvailableStorage": 0,
      "exTotalStorage": 0,
      "exAvailableStorage": 0,
      "osVersion": "4.2",
      "buildVersion": "1.01.08",
      "status": "APPROVAL_PENDING",
      "isDeleted": false,
      "policyIdNames": {
        "id": 3,
        "name": "Test Policy 3"
      },
      "deviceGroupIdNames": {
        "id": 1,
        "name": "Default Group"
      },
      "userIdName": {
        "id": 1,
        "name": "Randy Lewis"
      },
      "lastConnected": 1423810522000,
      "createdByIdName": {
        "id": 1,
        "name": "Randy Lewis"
      },
      "locked": false,
      "traceOn": false,
      "userEmail": "mdm.user1@gmail.com",
      "enrollmentDate": 1423790371000,
      "simNumbers": [
        "1236547896"
      ],
      "imeiCodes": [],
      "mobileNumbers": [
        "4558585858858"
      ],
      "createDate": 1422435030000,
      "lastModified": 1423810522000,
      "rooted": false,
      "roaming": false,
      "compliant": false
    },
    {
      "apiResponseStatus": "SUCCESS",
      "id": 26,
      "ownership": "CORPORATE",
      "deviceName": "Riffwire",
      "deviceType": "MOBILE",
      "osType": "IOS",
      "inTotalStorage": 0,
      "inAvailableStorage": 0,
      "exTotalStorage": 0,
      "exAvailableStorage": 0,
      "status": "PENDING",
      "isDeleted": false,
      "policyIdNames": {
        "id": 3,
        "name": "Test Policy 3"
      },
      "deviceGroupIdNames": {
        "id": 1,
        "name": "Default Group"
      },
      "userIdName": {
        "id": 1,
        "name": "Randy Lewis"
      },
      "createdByIdName": {
        "id": 1,
        "name": "Randy Lewis"
      },
      "locked": false,
      "traceOn": false,
      "userEmail": "mdm.user1@gmail.com",
      "simNumbers": [],
      "imeiCodes": [],
      "mobileNumbers": [],
      "createDate": 1422435030000,
      "lastModified": 1423216312000,
      "rooted": false,
      "roaming": false,
      "compliant": false
    },

此外,如果有好的选择,请提出建议。

您的问题是特定于JMeter的,但我相信它实际上是正则Json Path表达式。例如,在SoapUI中,它可以使用来完成

$.deviceResponseList[?(@.status=='PENDING')].id

这可能在某种程度上有助于

JMeter通过JMeter插件提供JSON路径提取器Extras With Libs Set

我相信这是实现目标的最佳方式。

有关插件安装说明和一些示例JSON路径查询,请参阅JMeter指南中的使用XPath提取器(向下滚动至"解析JSON"一章)。

相关内容

  • 没有找到相关文章

最新更新