ATLANTBH jmeter-components:JSON 路径断言 [英] ATLANTBH jmeter-components: JSON Path Assertion
问题描述
我正在尝试使用 ATLANTBH jmeter JSON PATH 断言执行 JSON 断言.
但是,我似乎无法编写正确的表达式来从下面发布的 JSON 提要中获取以下字段:
I'm trying to perform a JSON assertion using ATLANTBH jmeter JSON PATH Assertion.
However I cant seem to write a correct expression to get the following fields from the JSON feed posted below:
- 123456789
- 1009
一些随机消息
- 123456789
- 1009
SOME RANDOM MESSAGE
{"api": {"status":"Success","callsremaining":36,"version":"x.x.x.x"}
,"result":{"errors":{"123456789":{"code":1009,"error":"SOME RANDOM MESSAGE"}}}
}
这里有人有使用这个 JMeter 插件的经验吗?
我知道我可以使用 regex
和 Beanshell
来验证,但我宁愿使用这些 JSON 路径断言.
Has anyone here got any experience using this JMeter plugin?
I know I could use regex
and Beanshell
to validate but I'd rather use these JSON Path Assertion.
如果您能提供任何帮助,我们将不胜感激.
Any help you could provide would be most appreciated.
推荐答案
看起来您可以使用 JSONPath 表达式(在 JSON 中)轻松断言 1009
和 SOME RANDOM MESSAGE
值Path Assertion 组件)但不确定 123456789
:这不是节点值而是 bode 名称,这些组件使用的 JSONPath 实现似乎没有获取节点名称的表达式.
Looks like you can easily assert both 1009
and SOME RANDOM MESSAGE
values using JSONPath expressions (in JSON Path Assertion components) but not sure about 123456789
: that's not node value but bode name, and JSONPath implementation used by these components seems has no expressions to get node name.
假设您可以轻松地使用 123456789
来断言,而不是使用 jmeter 的标准 Response_Assertion.
Suppose you can easily use to assert 123456789
instead binding of JSON Path Extractor (from the same components collection) with jmeter's standard Response_Assertion.
将 2 个 JSON 路径断言作为子项添加到采样器,该采样器返回您要处理的 json 响应:
Add 2 JSON Path Assertions as children to the sampler which returns json response you want to process:
表达式将分别为 $.result.errors..code
和 $.result.errors..error
.
Expressions will be $.result.errors..code
and $.result.errors..error
correspondingly.
将 JSON Path Extractor 作为子项添加到同一个采样器以提取完整的错误条目:
Add JSON Path Extractor as child to the same sampler to extract full error entry:
表达式:$.result.errors.
.
这将提取 {"123456789":{"error":"SOME RANDOM MESSAGE","code":1009}}
并保存到指向的变量 (${errorKey}
>).
Expression: $.result.errors.
.
This will extract {"123456789":{"error":"SOME RANDOM MESSAGE","code":1009}}
and save into the pointed variable (${errorKey}
).
在之前添加 JSON 路径提取器之后,将响应断言作为子项添加到同一个采样器:
Add Response Assertion as child to the same sampler, after previously added JSON Path Extractor:
这将在 ${errorKey}
变量的值中声明密钥的名称 (123456789
).
This will assert name of the key (123456789
) in the value of ${errorKey}
variable.
<小时>
所以最终的结构可能看起来像
So the final construction may look like
...
YOUR Sampler
JSON Path Extractor
JSON Path Assertion
JSON Path Assertion
Response Assertion
...
这篇关于ATLANTBH jmeter-components:JSON 路径断言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!