前提
pip install requests
get与post请求

Requests响应
r.status_code 响应状态码
r.heards 响应头
r.cookies 响应cookies
r.text 响应文本
r. encoding 当前编码
r. content 以字节形式(二进制)返回
Requests扩充.
1:添加等待时间
requests.get(url,timeout=1) #超过等待时间则报错
2:添加请求头信息
requests.get(url,headers=headers) #设置请求头
3:添加文件
requests.post(url, files=files) #添加文件
文件传输
url = 'http://httpbin.org/post'
files = {'file': open('report.xls', 'rb')}
r = requests.post(url, files=files)
requests+pytest+allure
流程:
读取文件中的数据
requests拿到数据请求接口返回状态码
通过断言验证返回状态码和200对比
生成allure的测试报告
模块:
dataDemo(存放数据)>> readDemo(读取数据)
useRequests(发送请求)>>testDemo(生成报告)
读取csv文件流程
存储数据(csv)

读取数据

request请求接口返回状态码

python断言设置结合allure生成测试报告

测试报告展示

读取excle文件流程
存储数据
写入url,参数,请求方式

读取数据

request请求接口返回状态码

pytest断言设置结合allure生成测试报告

测试报告展示

本文介绍了如何利用Python的Requests库进行HTTP请求,包括GET和POST方法,以及如何设置超时、请求头和文件上传。同时,讲解了如何结合pytest和Allure生成详细的测试报告,包括从CSV和Excel文件读取数据,进行断言验证,并展示测试报告的流程。
567

被折叠的 条评论
为什么被折叠?



