Python+requests接口自动化测试脚本

使用Python+requests编写接口自动化测试脚本,需下载的类库有:requests,xlrd,xlutils

获取excel测试用例中的url和接口参数

1.获取excel文件
Python+requests接口自动化测试脚本.
TIPS:
1.path为excel的保存路径,且excel表最好以xls结尾

2.获取接口用例所在的工作表
Python+requests接口自动化测试脚本
3.获取url
Python+requests接口自动化测试脚本
TIPS:
1.total_row为总的url行数
2.url_col为url所在的列
3.用cell_value()方法来获取某个单元格的数据
4.获取参数
Python+requests接口自动化测试脚本

封装请求:get和post(需引入json库和requests库)

1.表单格式get请求
Python+requests接口自动化测试脚本
2.json格式post请求
Python+requests接口自动化测试脚本

写入结果(需引入xlutils)

Python+requests接口自动化测试脚本
TIPS:
1.resList[i][‘code’]这个取值是根据实际的reslist的格式来取
2.写入之后一定要保存!且保存的是workbook!

测试

Python+requests接口自动化测试脚本