每天进步一点点,关注我们哦,每天分享测试技术文章
本文章出自【码同学软件测试】
Postman的脚本可以导出多种语言的脚本,方便二次维护开发。
码同学公众号:自动化软件测试
码同学抖音号:小码哥聊软件测试
Python的requests库,支持python2和python3,用于发送http/https请求
使用unittest进行接口自动化测试
01 环境准备
1、安装python(使用python2或3都可以)
2、安装requests:pip install requests
电脑中同时存在python2和python3时会出现安装错误如下:

Python3下安装:

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

升级pip

成功安装requests

免费领取码同学软件测试课程笔记+超多学习资料+完整视频+最新面试题,可以转发文章+ 私信「码同学666」获取资料哦
Python2下成功安装requests

3、导出脚本:将postman的脚本转化成对应的python脚本
在postman主界面,点击code按钮打开导出脚本页面
选择对应的python下的requests语言(兼容python2和python3)
点击copy to clipboard(复制到粘贴板)按钮,成功复制脚本
新建记事本或者使用pycharm建立py文件,粘贴复制的内容


02
编写脚本
使用python自带的unittest框架:

脚本说明:
Response后面增加.json,是为了将相应结果转成json格式
使用for循环,遍历变量node_mane的列表值
插入断言assertEqual
END
免费领取码同学软件测试课程笔记+超多学习资料+学习完整视频,可以关注我们公众号哦:自动化软件测试
本文著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。
网友评论