接口自动化

一、jasonpath

import jsonpath
dic={
        "error_code": 0,
        "stu_info": [
                {
                        "id": 2057,
                        "name": "xiaohei",
                        "sex": "nan",
                        "age": 29,
                        "addr": "beijing",
                        "grade": "tianxie",
                        "phone": "18712321234",
                        "gold": 100
                }
        ]
}


s=jsonpath.jsonpath(dic,'$..age')
s2=jsonpath.jsonpath(dic,'$..error_code')
s3=jsonpath.jsonpath(dic,'$..abc')
print(s)
print(s2)
print(s3)
#如果取到的值不存在就返回False
 

二、分割参数

seqs=['!=','>=','<=','=','<','>','in','not']
#list循环这种的话,写用例的时候简单
s1='erro_code=0,name!=xxx,age>18'
s1_list = s1.split(',')
format_list=[]
for s in s1_list:
        for seq in seqs:
                if seq in s:
                        key,value = s.split(seq)
                        tmep = [key,seq,value]
                        format_list.append(tmep)
                        break

print(format_list)#[['erro_code', '=', '0'], ['name', '!=', 'xxx'], ['age', '>', '18']]

 

posted @ 2019-05-12 16:09  酷得像风  Views(129)  Comments(0Edit  收藏  举报