程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

0706 -- Python uses jsonpath to complete interface test automation parameter correlation and data verification

編輯:Python

Interface Association

Interface associations can usually use regular expressions to extract the required data , But for the JSON This simplicity 、 Clear hierarchy 、 Lightweight data interaction format , Using regular is a bit like killing a chicken with an ox knife ( Yes , Because I'm not good at writing regular expressions ), We need to be simpler 、 Direct extraction JSON The way of data .

 install :pip install jsonpath
Usage mode :jsonpath.jsonpath( A dictionary object ,jsonpath expression )
Return value : list .
"""
import jsonpath
resp = {
"code": 0,
"msg": "OK",
"data": {
"id": 200110,
"leave_amount": 4000.0,
"mobile_phone": "135000000002",
"reg_name": " Good name ",
"reg_time": "2020-06-29 11:52:20.0",
"type": 1,
"token_info": {
"token_type": "Bearer",
"expires_in": "2020-07-06 21:48:53",
"token": "7fJjnvS6xVw7_hYTe7eVIyxj3W2Oj7SlwR8dDZBc1T59U2ngRROXyFjx_Q"
}
},
"copyright": "Copyright"
}
# $.code
# Parameters : first : A dictionary object the second :jsonpath expression
# Return value : list . Store matches to all values .
# res = jsonpath.jsonpath(resp,"$.data.token_info.token")
# print(res)
a = jsonpath.jsonpath(resp,"$.copyright")[0]
print(a)

The first 44 A video explaining


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved