Jmeter json和正在提取及断言
一、提取所需要断言的内容:
响应数据如下:加入需要提取userid为10477的值
1 { 2 "pub": { 3 "status": 0, 4 "userId": "10477", 5 "apiVersion": "3.9.4.3004", 6 "subPline": "2", 7 "clientAgent": "svnVer_1907021457", 8 "channelCode": "AOT1001757", 9 "appCode": "f002", 10 "model": "ALP-AL00", 11 "imsi": "dz_1562222817068", 12 "imei": "dz_1562222817068", 13 "screen": "720x1206", 14 "os": "android28", 15 "pname": "com.ishugui12343", 16 "apn": "wifi", 17 "ip": "192.168.103.113", 18 "province": "北京市", 19 "city": "北京" 20 }, 21 "pri": { 22 "result": "0", 23 "tips": "验证码错误", 24 "account": [ 25 { 26 "coverWap": "", 27 "appid": "PHONE_NUM_VERIFY", 28 "nickname": "", 29 "id": "", 30 "key": "PHONE_NUM_VERIFY" 31 } 32 ] 33 } 34 }
1、sample添加-后置处理器-添加JSON Extracror(这里面需要稍微学习下json path espressions的语法了)--得到id的值90
自己看这个网址学习吧:http://goessner.net/articles/JsonPath/
2、也可以使用正则表达式提取
"userId":(.+?),
3.关联
下一个请求,使用提取的参数: ${userid_1} 或{userid_2}
二、断言提取出来的值
sample-断言-添加json assert
三、json path espressions的语法学习
$:跟对象元素
@:当前对象元素
?():应用过滤器(脚本)表达式
还是自己练习吧。。。。
{ "store": {
"book": [
{ "category": "reference",
"author": "Nigel Rees",
"title": "Sayings of the Century",
"price": 8.95
},
{ "category": "fiction",
"author": "Evelyn Waugh",
"title": "Sword of Honour",
"price": 12.99
},
{ "category": "fiction",
"author": "Herman Melville",
"title": "Moby Dick",
"isbn": "0-553-21311-3",
"price": 8.99
},
{ "category": "fiction",
"author": "J. R. R. Tolkien",
"title": "The Lord of the Rings",
"isbn": "0-395-19395-8",
"price": 22.99
}
],
"bicycle": {
"color": "red",
"price": 19.95
}
}
}
$.store.book[*].author:商店所有书籍的作者(四个作者)
$..author :所有作者
$.store.* :商店所有的东西,包括book和bicycle
$.store..price :所有东西的价格
$..book[2] :第三本书
$..book[0,1] /$..book[:2] :前两本书
$..book[?(@.isbn)] :用isbn编号过滤所有书籍
$..book[?(@.price<10)] :过滤所有比10更便宜的书
$..* :XML文档中的所有元素