接口测试 newman+postman+jenkins 学习笔记 (centos)

yangchun · 2019年07月21日 · 1389 次阅读

文字收藏:https://www.cnblogs.com/powertoolsteam/archive/2018/10/31/9881398.html

1 折买个百度云学习。。

图片

登录服务器

ssh root@106.13.31.247

安装 jenkins

安装jekins
https://www.cnblogs.com/loveyouyou616/p/8714544.html

坑:安装Jenkins时不能联网安装插件问题解决
https://blog.csdn.net/txyzqc/article/details/77885367

安装好以后启动jenkins
service jenkins start

安装 node

https://www.cnblogs.com/cerofang/p/9981698.html

npm 下载速度慢

npm config set -g registry https://registry.npm.taobao.org

安装 newman

npm install -g newman
npm install -g newman-reporter-html

postman 脚本复制到服务器

scp -r /Users/mac/Documents/data/test/newman/newman.postman_collection.json root@106.13.31.247:/root/yangchun/newman/newman.postman_collection.json

jenkins Build 中通过 shell 脚本去执行操作

  1. 新建项目

图片
2.构建脚本
图片


#!/bin/bash -il 
cd /opt/test/newman
newman run newman.postman_collection.json -e newman.postman_environment.json --reporters cli,html --reporter-html-export newman/index.html

#使用模板newman run -e my.environment.json -g my.globals.json --reporters cli,html --reporter-html-template templates/htmlreqres.hbs --reporter-html-export my_report.html my.collection.postman.json

#资料 https://github.com/MarcosEllys/awesome-newman-html-template

解决 newman not found 问题

图片

构建脚本加上
#!/bin/bash -il 

解决权限问题 permission denied

图片

#服务器上查找jenkins
find / -name "jenkins"

图片

#编辑文件 /etc/sysconfig/jenkins
JENKINS_USER=root

重启 jenkins

service jenkins restart

配置 HTML Report

  1. 安装 html publisher图片
  2. 构建后操作

图片

  1. 解决报错问题 ERROR: Specified HTML directory '/var/lib/jenkins/workspace/tujia/newman' does not exist. Build step 'Publish HTML reports' changed build result to FAILURE Finished: FAILURE 输出文件,放置于 jenkins workspace 中;脚本命令修改为 #!/bin/bash -il  cd /opt/test/newman newman run newman.postman_collection.json -e newman.postman_environment.json --reporters cli,html --reporter-html-export /var/lib/jenkins/workspace/tujia/newman/index.html 图片

解决 html report 格式问题

解决方案:https://testerhome.com/topics/11957?locale=en
构建成功了,但是格式太丑
图片
安装 Groovy 插件,重启 jenkins。请自行百度

使用管理员账号登录 jenkins,进入项目配置页 ==> Post Steps ==> 添加 Execute system Groovy script ==> 输入 System.setProperty("hudson.model.DirectoryBrowserSupport.CSP", "") ==> 保存

图片

导出 html report 成功啦,接下来就是设置定时任务和邮件啦
图片

暂无回复。
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册