读取响应正文并分配给 JMeter 中的一个变量

问题描述 投票:0回答:1

我需要从 JMeter 中的 Http 请求项之一返回的以下响应中读取 authId 值,并将其分配到 JSON extractor 下的一个变量中。 “我应该使用 $.ApiResponse.data.authId”来使其工作吗?

内容类型为 => Content-Type: application/json;字符集=utf-8

{"IsSuccess":true,"Message":"The one-time password (OTP) was successfully generated and sent.","Code":"ONE_TIME_PASSWORD_SUCCESS","ApiResponse":"{\"statusCode\":200,\"data\":{\"message\":\"OTP sent to your email.\",\"authId\":\"eyJ0eXAiOZWTc5NDAwLCJpYXQiOjE3MjE5Nzg4MDB9.LSQBtt7_cugRrxpA0l91UfwEAtAs0QXrB3dEvnPaNt4\",\"callbacks\":[{\"type\":\"TextOutputCallback\",\"output\":[{\"name\":\"message\",\"value\":\"OTP sent to your email.\"},{\"name\":\"messageType\",\"value\":\"0\"}]},{\"type\":\"ConfirmationCallback\",\"output\":[{\"name\":\"prompt\",\"value\":\"\"},{\"name\":\"messageType\",\"value\":0},{\"name\":\"options\",\"value\":[\"Yes. Continue Verify\",\"No. Resend new OTP\"]},{\"name\":\"optionType\",\"value\":-1},{\"name\":\"defaultOption\",\"value\":1}],\"input\":[{\"name\":\"IDToken2\",\"value\":0}]}],\"code\":\"ONE_TIME_PASSWORD_SUCCESS\",\"messageId\":\"APPOP201\",\"email\":\"ss****[email protected]\",\"csrfToken\":\"EjkS2HYV-snDQ2ddFkW861NNZGiv_ieGBsxTvXAKFd--eCvu6_sY\"},\"message\":\"OTP sent to your email.\"}"}

我尝试了很多正则表达式来使其工作,但它不起作用。然后我得到了一个使用 JSON_Extractor 的在线建议 https://jmeter.apache.org/usermanual/component_reference.html#JSON_Extractor

json regex jmeter
1个回答
0
投票

这样不行,JSON 中有 JSON,所以你需要 2 个 JSON 提取器

  1. 从响应数据中获取

    ApiResponse
    属性值,例如:

    enter image description here

  2. 从 ApiResponse

    JMeter 变量
    获取 authId,例如:

    enter image description here

更多信息:如何使用 JSON 提取器进行测试

© www.soinside.com 2019 - 2024. All rights reserved.