newman使用+allure生成报告

一、环境准备

  1. allure的安装
  2. 准备newman-reporter-allure
  3. newman安装

一.allure的安装
1.在github上下载allure包,解压
https://github.com/allure-framework/allure2/releases

2.环境变量的配置
(1)添加环境变量

vi ~/.bash_profile

(2)加入环境变量,路径为自己allure 的路径就好
在这里插入图片描述
(3)配置完成后,执行命令让环境变量生效

source ~/.bash_profile

(4)验证allure环境变量是否配置成功

allure --version

在这里插入图片描述
到此,allure安装配置成功。

二、newman-reporter-allure的安装
这个比较简单,没什么好说的。
使用命令行

npm install -g newman-reporter-allure

进行安装就好

三、newman的安装
这个是核心部分,但安装也是很简单的

npm install -g newman

主要是学习newman的使用,这些网上可以搜出一大堆

二、正式开始使用Newman

一、Postman的数据导出
1.通过集合导出所有请求
点击export即可
在这里插入图片描述
2.环境变量的导出
在这里插入图片描述
最后就得到两个json文件
在这里插入图片描述

二、newman的使用
1.简单使用newman

newman run json文件  [options]
例如: newman run OnlyMainPhoto.postman_collection.json

单纯的不要环境的脚本可以这样简单跑一跑,但实际中,应该都需要环境变量吧。

-e 参数可以把我们之前导出的环境变量用上。
-n iteration-count :指定迭代次数

newman run OnlyMainPhoto.postman_collection.json -e env.json -n 10

这样就可以了。

2.如果想仅运行集合里几个文件

可以使用 --folder [filename]来选择想运行的文件
newman run OnlyMainPhoto.postman_collection.json --folder 注册+approve -e env.json 

同理,如果运行多个文件,则添加多个–folder

newman run OnlyMainPhoto.postman_collection.json --folder 注册+approve --folder 注册+delete -e env.json 

3.运行中如果有环境变量的更改,那就再把环境导出去保存,下一次运行就好

通过 --export-environment env.json 又把环境更改了
newman run OnlyMainPhoto.postman_collection.json --folder 注册+approve --folder 注册+delete -e env.json  --export-environment env.json

4.添加证书

--ssl-client-cert [cert] --ssl-client-key [key] client-passphrase [passphrase]

我使用的是无passphrase的,如下:

newman run OnlyMainPhoto.postman_collection.json --folder 注册+approve  -e env.json  --export-environment env.json --ssl-client-cert client_cert.pem --ssl-client-key client_nopwd_key.pem

注意:如果集合里请求包含多个证书,那么就需要建立一个证书的json文件
在这里插入图片描述
在这里插入图片描述
然后在运行的时候添加

--ssl-client-cert-list [json文件]
newman run OnlyMainPhoto.postman_collection.json --folder 后台-login --folder 注册+approve -e env.json --ssl-client-cert-list ssl-list.json --export-environment env.json

到这里newman运行成功了。接下来就是生成测试报告了。
有很多种测试报告可以生成,这里用的allure,也是比较流行的一个吧。

三、allure测试报告的生成

1.newman run的时候添加参数

-r allure --reporter-allure-export [文件保存路径]
newman run OnlyMainPhoto.postman_collection.json --folder 后台-login --folder 注册+approve -e env.json --ssl-client-cert-list ssl-list.json --export-environment env.json -r allure --reporter-allure-export ./allure_report

这里直接保存当前文件下了。可以自己更改路径。
在这里插入图片描述
这保存的全是json和txt格式的文件,然后通过allure命令生成测试报告

2.生成测试报告

allure generate [原文件] -o [目的文件] --clean   生成allure测试报告

在这里插入图片描述
3.测试报告生成了,接下来打开就好

allure open [文件名]
Report successfully generated to allure_html
pofdeMacBook-Pro:Postman pof$ allure open allure_html/
Starting web server...
2021-07-16 12:24:19.495:INFO::main: Logging initialized @404ms to org.eclipse.jetty.util.log.StdErrLog
Server started at <http://192.168.50.232:55206/>. Press <Ctrl+C> to exit

在这里插入图片描述
ps. 这里的请求应该是你postman命名好的。但是newman-report-allure会弄成一堆乱码
可以参考:

https://www.cnblogs.com/landhu/p/14419555.html
在这里插入图片描述

可能有许多命令我没有用到,大家可以自己去搜啦。

  • 3
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值