目录
1、node.js
2、postman
3、newman
4、jenkins
5、svn
1、node.js
到官网下载
再进行默认安装nodejs,最后提示安装软件的路径,请先记住,newman时会用到;
验证nodejs是否安装成功,打开dos命令窗口,输入node -v,出现版本号,即安装成功了。
npm -v
配置环境变量
先查看环境变量,发现安装之后,环境变量自动添加了路径(Mac的node,npm可执行文件都在/usr/local/bin/目录下)
若需要添加环境变量,则vim .bash_profile
PATH=$PATH:/usr/local/bin/
:wq//保存并退出
source ~/.bash_profile 使修改能生效
2、postman
mac电脑直接进行客户端安装,在官网下载安装即可
3、newman
npm install -g newman
第一次安装,后查看版本newman -v,报找不到,发现安装失败,因此使用sudo 进行安装
安装html报告
npm install -g newman-reporter-html
本地运行脚本
newman run /Users/wanghuan/07-postman/02-test/04.postman_collection.json -e /Users/wanghuan/07-postman/02-test/url.postman_environment.json --reporters html --reporter-html-export /Users/wanghuan/07-postman/02-test/newman/repost.html
或
newman run /Users/wanghuan/07-postman/02-test/0401.postman_collection.json -e /Users/wanghuan/07-postman/02-test/url.postman_environment.json -g /Users/wanghuan/07-postman/02-test/g.postman_globals.json -r html --reporter-html-export /Users/wanghuan/07-postman/02-test/newman/repost4.html
注意:如果指定生成报告,就不显示具体的请求执行及结果。
了解命令行执行脚本
可以查看github上面的命令说明https://github.com/postmanlabs/newman#configuring-reporters、GitHub - postmanlabs/newman-reporter-html
run XX.json #执行脚本
---reporters html --reporter-html-export /路径 #导出执行结果到此路径,若指定输出报告,
-r html --reporter-html-export /路径
-e XX.json #带上环境变量
# 命令介绍
newman run 用例名称 [-e | -r | -d | -g -n - export-environment | -timeout (ms) | -timeport-request (ms) | -timeout-script (ms)]
-e等同于--environment:后面跟环境变量文件
-g等同于--globals:后面跟全局变量文件
-n等同于--iteration-count:设置迭代次数 postman参数化迭代测试
-d等同于--iteration-data:指定用于迭代的数据源文件(json,cvs)
-r等同于--reporters:后面跟数据结果,可以跟cli、html、json等
cli:直接在命令行打印结果
html:将结果生成为html文件,指定生成到具体目录需要配合--reporter-html-export 文件名使用
json:将结果生成为json文件,指定生成到具体目录需要配合--reporter-json-export 文件名使用
# -timeout (ms) 设置整个集合运行完成执行的时间
# –timeport-request (ms) 指定等待请求返回响应的时间
# -timeout-script (ms)指定等待脚本执行完成的时间
# --folder 运行collection中的指定folder
# --reporters html,json,junit 指定生成报告的类型
官方的文档介绍如下:https://learning.getpostman.com/docs/postman/collection_runs/command_line_integration_with_newman/
运行参数化:PostMan-NewMan运行参数 - happyyangyanghappy - 博客园原地址链接:https://brucelong.blog.csdn.net/article/details/89707536 PostMan-NewMan运行参数(二)一、Newman参数查看 1、在
https://www.cnblogs.com/happyyangyanghappy/p/15016466.html
直接在终端显示运行接口脚本的情况
newman run /Users/wanghuan/07-postman/02-test/04.postman_collection.json -e /Users/wanghuan/07-postman/02-test/url.postman_environment.json --bail newman
难点:遇到一个问题,当每个接口之间写了变量参数,在本地运行neman时,发现各接口不能互相传递变量参数,导致会有接口请求失败,目前没有找到解决方法。
4、jenkins
1、新建job,名字自己取即可
2、配置脚本:(需要在Jenkins服务器本地安装newman程序)
3、添加HTML报告:
4、运行job后查看报告:
自此,postman自动化测试可以顺利的跑起来了,邮件暂时没有添加,具体添加可以参考sonarqube中的配置。