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,作为生效的依据。

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

相关推荐
字节程序员9 小时前
JMeter 二次开发之环境准备
jmeter
测试杂货铺10 小时前
Jmeter压测实战:Jmeter二次开发之自定义函数
自动化测试·软件测试·测试工具·jmeter·职场和发展·测试用例·压力测试
字节程序员10 小时前
Jmeter对图片验证码的处理【超详细】
jmeter
测试老哥2 天前
Jmeter测试脚本编写技巧
自动化测试·软件测试·功能测试·测试工具·jmeter·职场和发展·性能测试
易思涯2 天前
【已解决】黑马点评项目jmeter高并发测试中用户数据的生成
jmeter·解决方法·黑马点评
霍格沃兹测试开发学社测试人社区2 天前
软件测试丨性能测试工具-JMeter
软件测试·测试开发·测试工具·jmeter·性能测试
字节程序员2 天前
Jmeter分布式压力测试
分布式·jmeter·压力测试
美团测试工程师2 天前
九大高效的前端测试工具与框架
软件测试·测试工具·jmeter
love静思冥想3 天前
JMeter 使用详解
java·jmeter
互联网杂货铺4 天前
几个常见的Jmeter压测问题
自动化测试·软件测试·测试工具·jmeter·职场和发展·测试用例·压力测试