安装requests
pip install requests
requests请求
1.get
# request.get(url,params,**kwargs)
# Demo:
import requests
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36"
}
params= {
"wd": "什么人"
}
url = "https://www.baidu.com/s"
r = requests.get(url, params, headers=headers)
print(r.url)
print(r.test)
2.post
# request.post(url,data,json,**kwargs)
# demo
url_juhe = 'http://apis.juhe.cn/springTravel/citys'
data = {'from':1,'to':2,'key':'9f5b693b556edb4325ff0560f85c95e8'}
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36"
}
import requests
r = requests.post(url=url, data=data,headers=headers)
print(r.json())
常用的响应方法
r.status_code 响应状态码
r.heards 响应头
r.cookies 响应cookies
r.text 响应文本
r.encoding 当前编码
r.content 以字节形式(二进制)返回
requests+pytest+allure生成测试报告
读取文件中的数据 requests拿到数据请求接口返回状态码 通过断言验证返回状态码和200对比 生成allure的测试报告
.xlsx
测试用例
测试代码
读取excel
启动测试用例
结果结果试报告
.csv
测试用例
读csv文件
测试的代码
启动测试用例