-1

我想根据条件“status”:“Ready for Review”从 HTTP 采样器的以下 JSON 响应正文获取“currentApproversStr:”的值,并传递给以下 HTTP 采样器。

我尝试了以下但它不工作

  1. 创建变量的名称:currentApproversStr
  2. JSON 路径表达式:$.[?((@.currentApproversStr == "Validation, Civa" || @.currentApproversStr == "Validation, Darla" || @.currentApproversStr == "Validation, Bittl" || @.currentApproversStr = = "验证,查" || @.currentApproversStr == "验证,巴内特") && @.status== "准备审核")]
  3. 比赛编号:-1 或 1

但 Dummy Sampler 会返回结果

我们不能保证具有“状态”的“timecardId”块的顺序:“Ready for Review”,即有时排在第二位,有时排在最后。这是第二个街区。所以不确定匹配号:我应该给什么 在此处输入图像描述

[
  {
    "timecardId": 170803,
    "entryHeaderId": "db9341a9-32e8-4d45-a858-a88b75a42cef",
    "startsOn": "2021-10-24T00:00:00",
    "endsOn": "2021-10-30T00:00:00",
    "worksightStatus": "SignedOff",
    "projectId": 1977,
    "userId": 60874,
    "status": "Submitted for Approval",
    "batchId": 39814,
    "emergencyType": "",
    "htgDealMemoId": "0d0ff42b-5c4b-4695-b527-34dfc64585e5",
    "unionId": "1c77c660-28fc-4e40-b557-132f3da39597",
    "currentApproversStr": "Perf, PA",
    "commentStr": "",
    "commentUserName": "",
    "commentCreatedAt": "1900-01-01T00:00:00",
    "occupationCode": "TECHNICIAN",
    "activeApprovalFlowId": 166669,
    "isAllowanceOnly": false,
    "departmentId": null,
    "datePosted": null
  },
  {
    "timecardId": 170807,
    "entryHeaderId": "c9809446-b01f-4f42-add6-9b441c3d0114",
    "startsOn": "2021-10-17T00:00:00",
    "endsOn": "2021-10-23T00:00:00",
    "worksightStatus": "Outstanding",
    "projectId": 1977,
    "userId": 60874,
    "status": "Ready for Review",
    "batchId": 39815,
    "emergencyType": "",
    "htgDealMemoId": "0d0ff42b-5c4b-4695-b527-34dfc64585e5",
    "unionId": "1c77c660-28fc-4e40-b557-132f3da39597",
    "currentApproversStr": "Validation, Civa",
    "commentStr": "",
    "commentUserName": "",
    "commentCreatedAt": "1900-01-01T00:00:00",
    "occupationCode": "TECHNICIAN",
    "activeApprovalFlowId": 166674,
    "isAllowanceOnly": false,
    "departmentId": null,
    "datePosted": null
  },
  {
    "timecardId": 170802,
    "entryHeaderId": "db9341a9-32e8-4d45-a858-a88b75a42cef",
    "startsOn": "2021-10-24T00:00:00",
    "endsOn": "2021-10-30T00:00:00",
    "worksightStatus": "SignedOff",
    "projectId": 1977,
    "userId": 60874,
    "status": "Submitted for Approval",
    "batchId": 39814,
    "emergencyType": "",
    "htgDealMemoId": "0d0ff42b-5c4b-4695-b527-34dfc64585e5",
    "unionId": "1c77c660-28fc-4e40-b557-132f3da39597",
    "currentApproversStr": "Perf, PA",
    "commentStr": "",
    "commentUserName": "",
    "commentCreatedAt": "1900-01-01T00:00:00",
    "occupationCode": "TECHNICIAN",
    "activeApprovalFlowId": 166669,
    "isAllowanceOnly": false,
    "departmentId": null,
    "datePosted": null
  }
]

在此处输入图像描述

在此处输入图像描述 在此处输入图像描述

4

2 回答 2

0

“匹配号”的工作原理如下:如果您的查询返回超过 1 个结果:

  1. 0- 返回随机结果

  2. -1- 以下列形式返回所有结果:

    • currentApproversStr_1- 第一场比赛
    • currentApproversStr_2- 第二场比赛
    • 等等
    • currentApproversStr_matchNr- 比赛总数
  3. any positive integer- 返回给定的匹配

它不仅适用于JSON Extractor ,还适用于从响应中提取值的所有其他JMeter PostProcessor 。

您可以使用Debug Sampler 和 View Results Tree 侦听器组合查看生成的JMeter 变量

在此处输入图像描述

于 2021-10-15T07:37:19.983 回答
0

问题: 原因是您误解了 JSON 提取器的工作方式。此功能允许您在一个设置中提取许多变量,但 number of Names of created variables= number of JSON Path expressions= number of Default Values

例如,您要提取 2 个变量:

  • 创建变量的名称:var_name_1;var_name_2

  • JSON 路径表达式:json_expression_1;json_expression_2

  • 默认值:default_1;default_2

(注意:记住使用分号 (;) 分隔值)

但是您设置了1 个变量,1 个具有许多默认值的 json 表达式--> 不匹配。

解决方案: 您可以这样设置:

Names of created variables: currentApproversStr
JSON Path expressions: $.[?(@.status== "Ready for Review")].currentApproversStr
Match No: -1
Default Values: NOT_FOUND

结果:

currentApproversStr_1=Validation, Civa
currentApproversStr_matchNr=1
于 2021-10-16T04:14:54.390 回答