JMeter后置处理器之JSON提取器

1、添加json提取器

【线程组】------>【添加】------>【后置处理器】

2、JSON提取器面板介绍

  • Main sampleand sub-samples:应用于主sample及子sample
  • Main sample only:默认的是这个,应用于主sample
  • Sub-samples only:应用于子sample
  • JMeterVariableName to use:应用于变量命名的内容
  • Variable names : 名称
  • JSONPath Expression:JSON表达式
  • Match Numbers:0随机;n取第几个匹配值;-1匹配所有,后续引用用 变量名_N 取第N个值
  • Default Value:未取到值的时候默认值

3、json提取器提取方法介绍:

txt 复制代码
$.你要提取的参数

1、响应类似{"属性":[{"sx":1},{},{}]},整个响应是个对象。取sx的值:$.属性[0].sx

2、修改json extractor 获取数组的所有值   $[*].属性。match no=3取第3个

3、match no=5,数组越界后,取default values

4、修改json extractor  设置match no =-1 匹配对应字段所有值;并修改接收参数的http请求的参数为 ${varname_N}。N=1-4
txt 复制代码
我想提取code参数值:
JSON Path Extractor:$.code

提取username参数值:
JSON Path Extractor:$.list[0].username
 

如果提取的参数不存在父级?
$.你要提取的参数名

提取的参数存在父级
$.你要提取的参数名的父亲.你要提取的参数名

如果提取参数的父级存在父级
$.你要提取的参数名的父亲的父亲(爷爷).你要提取的参数名的父亲.你要提取的参数名

参数如果是数组?
$.你要提取的参数参数[N]

以下标的形式取值,0代表取的数组中第一个值,1代表取的是数组中第二个值,N代表取的数组中第N+1个值

4、提取(单个值)

json 复制代码
{
    "path": "\/api\/ou\/org\/tree",
    "data": [
        {
            "dLevel": "0",
            "isAble": "1",
            "city": null,
            "creatorId": null,
            "updateTime": 1615276836000,
            "remark": null,
            "sort": 0,
            "type": null,
            "parentId": "1",
            "dLevelCode": "000001",
            "province": null,
            "createTime": 1615276836000,
            "reviserId": null,
            "simpleName": "测试",
            "children": null,
            "tenantId": "",
            "name": "测试数据",
            "contactNumber": null,
            "id": "3f28875b7815fda40178160086c80008",
            "deptCode": "meritdata"
        }
    ],
    "success": true,
    "message": "成功",
    "stackmessage": null,
    "timestamp": 1620357542328,
    "status": 1,
    "extraInfo": {
    }
}
  • 如下所示,是一个提取单个值的示例。

5、提取(多个值)

提取多个值得json内容和提取单个值得格式保持一致,多个之间分别用分号来隔开

样例数据

json 复制代码
{
    "path": "\/api\/ou\/org\/tree",
    "data": [
        {
            "dLevel": "0",
            "isAble": "1",
            "city": null,
            "creatorId": null,
            "updateTime": 1616567075000,
            "remark": null,
            "sort": 1,
            "type": null,
            "parentId": "3f28875b7815fda40178160086c80008",
            "dLevelCode": "000001000002",
            "province": null,
            "createTime": 1616567075000,
            "reviserId": null,
            "simpleName": "aaaa",
            "children": null,
            "tenantId": "",
            "name": "aaaa",
            "contactNumber": null,
            "id": "3f28875b783e17df017862e80146007b",
            "deptCode": "aaaa"
        },
        {
            "dLevel": "0",
            "isAble": "1",
            "city": null,
            "creatorId": null,
            "updateTime": 1620295113000,
            "remark": "",
            "sort": 1,
            "type": null,
            "parentId": "3f28875b7815fda40178160086c80008",
            "dLevelCode": "000001000003",
            "province": null,
            "createTime": null,
            "reviserId": null,
            "simpleName": "test001",
            "children": null,
            "tenantId": "",
            "name": "test001",
            "contactNumber": null,
            "id": "3f28875b791718ac01792163c22c002e",
            "deptCode": "test001"
        },
        {
            "dLevel": "0",
            "isAble": "1",
            "city": null,
            "creatorId": null,
            "updateTime": 1620355231000,
            "remark": null,
            "sort": 1,
            "type": null,
            "parentId": "3f28875b7815fda40178160086c80008",
            "dLevelCode": "000001000004",
            "province": null,
            "createTime": 1620355231000,
            "reviserId": null,
            "simpleName": "test_001",
            "children": null,
            "tenantId": "",
            "name": "test_001",
            "contactNumber": null,
            "id": "3f28875b793f33c5017944b2b0a104f7",
            "deptCode": "test_001"
        },
        {
            "dLevel": "0",
            "isAble": "1",
            "city": null,
            "creatorId": null,
            "updateTime": 1620355231000,
            "remark": null,
            "sort": 2,
            "type": null,
            "parentId": "3f28875b7815fda40178160086c80008",
            "dLevelCode": "000001000005",
            "province": null,
            "createTime": 1620355231000,
            "reviserId": null,
            "simpleName": "test_002",
            "children": null,
            "tenantId": "",
            "name": "test_002",
            "contactNumber": null,
            "id": "3f28875b793f33c5017944b2b0ef04f9",
            "deptCode": "test_002"
        },
        {
            "dLevel": "0",
            "isAble": "1",
            "city": null,
            "creatorId": null,
            "updateTime": 1620355232000,
            "remark": null,
            "sort": 3,
            "type": null,
            "parentId": "3f28875b7815fda40178160086c80008",
            "dLevelCode": "000001000006",
            "province": null,
            "createTime": 1620355232000,
            "reviserId": null,
            "simpleName": "test_003",
            "children": null,
            "tenantId": "",
            "name": "test_003",
            "contactNumber": null,
            "id": "3f28875b793f33c5017944b2b12e04fb",
            "deptCode": "test_003"
        },
        {
            "dLevel": "0",
            "isAble": "1",
            "city": null,
            "creatorId": null,
            "updateTime": 1620355232000,
            "remark": null,
            "sort": 4,
            "type": null,
            "parentId": "3f28875b7815fda40178160086c80008",
            "dLevelCode": "000001000007",
            "province": null,
            "createTime": 1620355232000,
            "reviserId": null,
            "simpleName": "test_004",
            "children": null,
            "tenantId": "",
            "name": "test_004",
            "contactNumber": null,
            "id": "3f28875b793f33c5017944b2b1ab04fd",
            "deptCode": "test_004"
        },
        {
            "dLevel": "0",
            "isAble": "1",
            "city": null,
            "creatorId": null,
            "updateTime": 1620355232000,
            "remark": null,
            "sort": 5,
            "type": null,
            "parentId": "3f28875b7815fda40178160086c80008",
            "dLevelCode": "000001000008",
            "province": null,
            "createTime": 1620355232000,
            "reviserId": null,
            "simpleName": "test_005",
            "children": null,
            "tenantId": "",
            "name": "test_005",
            "contactNumber": null,
            "id": "3f28875b793f33c5017944b2b20804ff",
            "deptCode": "test_005"
        },
        {
            "dLevel": "0",
            "isAble": "1",
            "city": null,
            "creatorId": null,
            "updateTime": 1620355232000,
            "remark": null,
            "sort": 6,
            "type": null,
            "parentId": "3f28875b7815fda40178160086c80008",
            "dLevelCode": "000001000009",
            "province": null,
            "createTime": 1620355232000,
            "reviserId": null,
            "simpleName": "test_006",
            "children": null,
            "tenantId": "",
            "name": "test_006",
            "contactNumber": null,
            "id": "3f28875b793f33c5017944b2b2660501",
            "deptCode": "test_006"
        }
    ],
    "success": true,
    "message": "成功",
    "stackmessage": null,
    "timestamp": 1620357542356,
    "status": 1,
    "extraInfo": {
    }
}

6、动态传值(多个值)

使用场景: 场景包含多个接口,多个接口有参数传递;

样例场景: 测试数据创建创景,包含新建模型、导入属性、生效模型三个主要接口,其中生效模型接口需要拿到新建模型完成后的模型名称和id,作为生效的依据。

为后续的自动化提供便利。。。。。。

相关推荐
sszmvb123417 小时前
测试开发 | 电商业务性能测试: Jmeter 参数化功能实现注册登录的数据驱动
jmeter·面试·职场和发展
小码哥说测试19 小时前
接口测试用例设计的关键步骤与技巧解析!
自动化测试·测试工具·jmeter·职场和发展·测试用例·接口测试·postman
小钱c71 天前
Mac下安装Apache JMeter并启动
jmeter·macos·apache
古人诚不我欺1 天前
jmeter常用配置元件介绍总结之函数助手
jmeter
川石课堂软件测试1 天前
性能测试|docker容器下搭建JMeter+Grafana+Influxdb监控可视化平台
运维·javascript·深度学习·jmeter·docker·容器·grafana
古人诚不我欺1 天前
jmeter常用配置元件介绍总结之取样器
jmeter
十叶知秋1 天前
【jmeter】jmeter的线程组功能的详细介绍
数据库·jmeter·性能测试
我非夏日1 天前
JMeter基础篇
jmeter
茶馆大橘1 天前
微服务系列五:避免雪崩问题的限流、隔离、熔断措施
java·jmeter·spring cloud·微服务·云原生·架构·sentinel
土小帽软件测试2 天前
jmeter基础01-2_环境准备-Mac系统安装jdk
java·测试工具·jmeter·macos·软件测试学习