接口测试框架
一、编写第一个接口测试用例(接口测试网站:https://httpbin.testing-studio.com/get)

1.1、命名规范,py文件名test_xxx;类名:Test_xxx,方法名:test_xxx
1.2、配置pytest
①在Settings中输入pytest搜索,在Tools下的Python Integrated Tools-Testing-Default test runner选择pytest

②删掉之前跑脚本的方法


③重启pycharm

二、接口请求构造
2.1、请求目标构造:r = requests.get('https://httpbin.testing-studio.com/get')
get:请求方法;
https://httpbin.testing-studio.com/get是请求地址
query中的get请求多了一个params,form中的post请求多了一个data

三、接口测试断言
3.1、基本信息:r.url、r.status_code、r.headers、r.cookies
3.2、’响应结果
r.text = r.encoding + r.content #(编码+内容)
r.json() = r.encoding + r.content +content type json
3.3、header构造
普通的header:
headers = {‘user-agent’:'my-app/0.0.1}
r = requests.get(url,headers=headers)
cookie
cookies = dict(cookies_are = 'working')
r = request.get(url, cookies = cookies)

四、json
4.1JSON请求体构造
payload = { 'some':'data'}
r = requests.post(url, json = payload)

4.2结构化响应断言JSON
数据量比较多时的断言

使用jsonpath进行更加简便的书写
安装jsonpath库
语法:
$..(所有的内容)
$..id(所有内容的id)
($..id)[0],所有内容的第一个id
print(r.json(),'$..id'),打印所有内容的Id值
