当前位置:网站首页>性能测试(05)-表达式和业务关联-json关联
性能测试(05)-表达式和业务关联-json关联
2022-08-09 10:45:00 【猿小飞】
1.使用场景
在对返回结果较复杂且为json结构的HTTP请求进行提取某一个值,以用作其他接口使用或者用来断言的等。
2.使用
添加步骤:选择线程组中的HTTP请求——右键“添加”——后置处理器——JSON Extractor
先来一个免费的API网站:API Shop,专业的数据交易平台 | API免费调用,行业数据下载,数据定制
到时候,一般的测试数据,我们就直接从这个网站中获取就好。
{
"result": {
"area": "广州",
"areaCode": "440100",
"areaid": "101280101",
"dayList": [{
"area": "广州",
"night_wind_direction": "东北风",
"night_air_temperature": "13",
"night_weather_pic": "http:\/\/app1.showapi.com\/weather\/icon\/night\/07.png",
"day_weather_code": "01",
"night_weather": "小雨",
"night_weather_code": "07",
"day_weather": "多云",
"day_wind_power": "0-3级",
"day_air_temperature": "18",
"day_weather_pic": "http:\/\/app1.showapi.com\/weather\/icon\/day\/01.png",
"day_wind_direction": "东北风",
"areaCode": "440100",
"areaid": "101280101",
"night_wind_power": "3-4级",
"daytime": "20211219"
},
{
"area": "广州",
"night_wind_direction": "东北风",
"night_air_temperature": "12",
"night_weather_pic": "http:\/\/app1.showapi.com\/weather\/icon\/night\/21.png",
"day_weather_code": "07",
"night_weather": "小到中雨",
"night_weather_code": "21",
"day_weather": "小雨",
"day_wind_power": "3-4级",
"day_air_temperature": "15",
"day_weather_pic": "http:\/\/app1.showapi.com\/weather\/icon\/day\/07.png",
"day_wind_direction": "东北风",
"areaCode": "440100",
"areaid": "101280101",
"night_wind_power": "3-4级",
"daytime": "20211220"
}
],
"ret_code": 0
},
"statusCode": "000000",
"desc": "请求成功"
}
接着我们就创建一个JSON提取器。
参数说明:
Variable names(名称):提取器的名称
Apply to(应用范围):
Main sample and sub-samples:应用于主sample及子sample。
Main sample only:默认的是这个,应用于主sample。
Sub-samples only:应用于子sample。
JMeter Variable :应用于变量命名的内容。
Variable names:保存的变量名,后面使用${Variable names}引用。
JSON Path expressions:上一步中调试通过的json path表达式。
Match Numbers:匹配数字(0代表随机,1代表第一个,-1代表所有)。
Default Values:找不到时默认值,一般设置为NOT FOUND。
Compute concatenation var(suffix_ALL):是否统计所有,即将匹配到的所有值保存,名为“变量名_ALL”,使用场景需要获取的值有多个,后面需要对这一组数据进行操作。
特别注意:
当json提取器要提取两个值(或两个以上)的时候,一定要填写默认值,不然会报错
“Mismatch between number of variables, json expressions and default values” ;
反之:只提取两个值,默认值填了三个,也会报该错。
3.JSON Path expressions中的参数详细
JsonPath | 描述 |
$ | 根节点 |
@ | 当前节点 |
.or[] | 子节点 |
.. | 选择所有符合条件的节点 |
* | 所有节点 |
[] | 迭代器标示,如数组下标 |
[,] | 支持迭代器中做多选 |
[start:end:step] | 数组切片运算符 |
?() | 支持过滤操作 |
() | 支持表达式计算 |
4.配置
5.结果
6.获取上一个请求结果进行请求
7. jsonpath 语法
$..Name:列出所有省份
8.Json 取多个变量


也可以用表达式匹配所有值,然后用 match no 获取想要的值
边栏推荐
- torch.cat()函数的官方解释,详解以及例子
- Shell script combat (2nd edition) / People's Posts and Telecommunications Press Script 2 Validate input: letters and numbers only
- 【报错记录】解决华擎J3455-ITX不插显示器无法开机的问题
- 1005 继续(3n+1)猜想 (25 分)
- MySQL和MyEclipse的数据库连接操作
- Win32控件------------显示系统使用的控件版本
- Dialogue with the DPO of a multinational consumer brand: How to start with data security compliance?See you on 8.11 Live!
- CSDN的markdown编辑器语法完整大全
- xmms已经发布到v1.3了,好久没写博客了
- unix环境编程 第十五章 15.7消息队列
猜你喜欢
商业技术解决方案与高阶技术专题 - 数据可视化专题
深度学习--自编码器(AutoEncoder)
MNIST机器学习入门
shap库源码和代码实现
Cluster understanding
使用cpolar远程连接群晖NAS(创建临时链接)
Solve the ali cloud oss - the original 】 【 exe double-click response can't open, to provide a solution
【 original 】 VMware Workstation implementation Openwrt soft routing, the ESXI, content is very detailed!
机器学习-逻辑回归(logistics regression)
shell脚本实战(第2版)/人民邮电出版社 脚本1 在PATH中查找程序
随机推荐
xmms的歌词显示及音量控制OK
力扣(LeetCode)220. 存在重复元素 III(2022.08.08)
关于anaconda中conda下载包或者pip下载包很慢的原因,加速下载包的方法(无视anaconda版本和环境)
The complete grammar of CSDN's markdown editor
Mysql多表查询
强化学习 (Reinforcement Learning)
RPN principle in faster-rcnn
编程技术提升
Oracle数据库常用函数总结
MNIST机器学习入门
OpenSSF的开源软件风险评估工具:Scorecards
相关系数计算,热力图绘制,代码实现
山东招远通报星童幼儿园食品安全问题最新调查情况
OpenGL ES2.0编程三部曲(转载自MyArrow)
activemq 消息持久化
Pyhton实战汇总篇
机器学习--朴素贝叶斯(Naive Bayes)
Solve the ali cloud oss - the original 】 【 exe double-click response can't open, to provide a solution
机器学习--线性回归(Linear Regression)
UNIX Environment Programming Chapter 15 15.5FIFO