12.Postman 导出python脚本进行数据驱动的接口测试

Postman的脚本可以导出多种语言的脚本,方便二次维护开发

Python的requests库,支持python2和python3,用于发送http/https请求

使用unittest进行接口自动化测试

 

环境准备:

1.安装python(使用python2或3都可以)

2.安装requests:pip install requests

电脑中同时存在python2和python3时会出现安装错误如下:

12.Postman 导出python脚本进行数据驱动的接口测试

Python3下安装:

12.Postman 导出python脚本进行数据驱动的接口测试

Pip的版本太低,无法安装其他模块

12.Postman 导出python脚本进行数据驱动的接口测试

升级pip

12.Postman 导出python脚本进行数据驱动的接口测试

成功安装requests

12.Postman 导出python脚本进行数据驱动的接口测试

Python2下成功安装requests

12.Postman 导出python脚本进行数据驱动的接口测试

3.导出脚本:将postman的脚本转化成对应的python脚本

       在postman主界面,点击node按钮打开导出脚本页面

选择对应的python下的requests语言(兼容python2和python3)

点击copy to clipboard(复制到黏贴板)按钮,成功复制脚本

新建记事本或者使用pycharm建立py文件,黏贴复制的内容

12.Postman 导出python脚本进行数据驱动的接口测试

12.Postman 导出python脚本进行数据驱动的接口测试

编写脚本

使用python自带的unittest框架

12.Postman 导出python脚本进行数据驱动的接口测试

脚本说明:

Response后面增加.json,是为了将相应结果转成json格式

使用for循环,遍历变量node_mane的列表值

插入断言assertEqual