Postman的安装与使用
参考前面的文章:接口测试工具:Postman的安装与使用
Newman安装
需要安装node.js,并配置好环境,下载地址:https://nodejs.org/en/打开cmd,安装newman。
npm install -g newman
3. 安装好使用命令newman -v查看是否安装成功。 4. 安装html插件
npm install -g newman-reporter-html
安装美化测试报告
npm install -g newman-reporter-htmlextra
5. newman 常用命令
newman run 运行命令
常用参数:
-h 显示命令行帮助,包括选项列表和简单的使用案例。
-v 显示当前newman的版本
-e 引用环境变量
-g 引用全局变量
-d 引用数据文件
-r 表示生成报告的文件类型,cli,xml,json,junit,html,htmlextra
--reporter-html-export 生成html格式的测试报告。
--reporter-htmlextra-export 生成htmlextra格式的测试报告。
newman run 脚本名 -e 环境变量名 -g 全局变量名 -d 数据驱动文件名 -r cli,html,json,junit --reporter-html-export 报告名.html
Postman+Newman实战
以项目的登录接口为示例,使用csv或json文件做数据驱动
接口参数使用变量写好,需要与文件里设置的变量名一致。 登录接口,我准备了三组数据 用例1:正确的用户名,正确的密码 用例2:正确的用户名,错误的密码 用例3:错误的用户名,正确的密码 若使用json文件做数据驱动,格式为: 若使用csv文件做数据驱动,格式为: 对三个用例分别做断言,在Tests编写如下代码: 导出Collection,选择postman默认的版本即可;
导出环境变量;
如果有全局变量还需要导出全局变量,我这边没有,就不用导出。
运行
newman run "D:\Demo.postman_collection.json" -e "D:\sit1.postman_environment.json" -d D:\data.json -r cli,htmlextra --reporter-htmlextra-export loginreport.html
执行结果: HTML报告:
若有更好的实践方式,或者有需优化的地方,劳烦评论区告之~~
相关链接
发表评论