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文檔中的所有元素