ATLANTBH jmeter-components:JSON路径声明 [英] ATLANTBH jmeter-components: JSON Path Assertion

查看:196
本文介绍了ATLANTBH jmeter-components:JSON路径声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 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:

  1. 123456789
  2. 1009
  3. 一些随机消息

  1. 123456789
  2. 1009
  3. SOME RANDOM MESSAGE

{"api": {"status":"Success","callsremaining":36,"version":"x.x.x.x"}
,"result":{"errors":{"123456789":{"code":1009,"error":"SOME RANDOM MESSAGE"}}}
}

这里有人有使用此JMeter插件的经验吗?
我知道我可以使用regexBeanshell进行验证,但我更愿意使用这些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 Path Assertion组件中)轻松声明1009SOME RANDOM MESSAGE值,但不确定123456789:这不是节点值,而是波特值,这些组件使用的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的标准

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.

  1. 将2个JSON路径断言作为子项添加到采样器,该采样器返回要处理的json响应:

  1. Add 2 JSON Path Assertions as children to the sampler which returns json response you want to process:

表达式将分别为$.result.errors..code$.result.errors..error.

将JSON路径提取器作为子项添加到同一采样器以提取完整的错误条目:

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屋!

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