jmeter之--斷言json響應&json path espressions的語法
阿新 • • 發佈:2017-08-03
啊啊啊 練習 所有 images bsp 表達式 ons author sse
一、提取所需要斷言的內容:
響應數據如下:加入需要提取id為90的值
{
"id" : 90,
"name" : "python",
"url" : "http://www.v2ex.com/go/python",
"title" : "Python",
"title_alternative" : "Python",
"topics" : 7428,
"stars" : 4776,
"header" : "這裏討論各種 Python 語言編程話題,也包括 Django,Tornado 等框架的討論。這裏是一個能夠幫助你解決實際問題的地方。 ",
"footer" : null,
"created" : 1278683336,
"avatar_mini" : "//v2ex.assets.uxengine.net/navatar/8613/985e/90_mini.png?m=1501663676",
"avatar_normal" : "//v2ex.assets.uxengine.net/navatar/8613/985e/90_normal.png?m=1501663676",
"avatar_large" : "//v2ex.assets.uxengine.net/navatar/8613/985e/90_large.png?m=1501663676 "
}
1、sample添加-後置處理器-添加JSON Extracror(這裏面需要稍微學習下json path espressions的語法了)--得到id的值90
自己看這個網址學習吧:http://goessner.net/articles/JsonPath/
2、也可以使用正則表達式提取
"id":(.+?),
二、斷言提取出來的值
sample-斷言-添加json path assert(前提是要安裝這個包啊啊啊)
三、json path espressions的語法學習
$:跟對象\元素
@:當前對象\元素
?():應用過濾器(腳本)表達式
還是自己練習吧。。。。
1 { "store": {
2 "book": [
3 { "category": "reference",
4 "author": "Nigel Rees",
5 "title": "Sayings of the Century",
6 "price": 8.95
7 },
8 { "category": "fiction",
9 "author": "Evelyn Waugh",
10 "title": "Sword of Honour",
11 "price": 12.99
12 },
13 { "category": "fiction",
14 "author": "Herman Melville",
15 "title": "Moby Dick",
16 "isbn": "0-553-21311-3",
17 "price": 8.99
18 },
19 { "category": "fiction",
20 "author": "J. R. R. Tolkien",
21 "title": "The Lord of the Rings",
22 "isbn": "0-395-19395-8",
23 "price": 22.99
24 }
25 ],
26 "bicycle": {
27 "color": "red",
28 "price": 19.95
29 }
30 }
31 }
$.store.book[*].author:商店所有書籍的作者(四個作者)
$..author :所有作者
$.store.* :商店所有的東西,包括book和bicycle
$.store..price :所有東西的價格
$..book[2] :第三本書
$..book[0,1] /$..book[:2] :前兩本書
$..book[?(@.isbn)] :用isbn編號過濾所有書籍
$..book[?(@.price<10)] :過濾所有比10更便宜的書
$..* :XML文檔中的所有元素
jmeter之--斷言json響應&json path espressions的語法