Postman+Newman+Jenkins实现webapi接口回归测试

1、在postman上创建项目

postman入门使用教程参见https://www.jianshu.com/p/4d380f1a3fe0

2、上传本地源码到远程仓库

参考文档https://blog.csdn.net/u010412719/article/details/72860193

常用git命令:https://coding.net/help/doc/git/push.html

1)shifangfangdeMacBook-Pro:~ shifangfang$ mkdir postman_test

shifangfangdeMacBook-Pro:~ shifangfang$ cd postman_test/

shifangfangdeMacBook-Pro:postman_test shifangfang$ git init

Initialized empty Git repository in /Users/shifangfang/postman_test/.git/

shifangfangdeMacBook-Pro:postman_test shifangfang$ git add ~/Desktop/pro_env_order.postman_collection.json

fatal: /Users/shifangfang/Desktop/pro_env_order.postman_collection.json: '/Users/shifangfang/Desktop/pro_env_order.postman_collection.json' is outside repository

shifangfangdeMacBook-Pro:gitdemo shifangfang$ cd ~/postman_test/

shifangfangdeMacBook-Pro:postman_test shifangfang$ ls

shifangfangdeMacBook-Pro:postman_test shifangfang$ cp ~/Desktop/pro_env_order.postman_collection.json ./

shifangfangdeMacBook-Pro:postman_test shifangfang$ ls

pro_env_order.postman_collection.json

shifangfangdeMacBook-Pro:postman_test shifangfang$ cp ~/Desktop/pro_env.postman_environment.json ./

shifangfangdeMacBook-Pro:postman_test shifangfang$ ls

pro_env.postman_environment.json pro_env_order.postman_collection.json

shifangfangdeMacBook-Pro:postman_test shifangfang$ git add pro_env_order.postman_collection.json

shifangfangdeMacBook-Pro:postman_test shifangfang$ git add pro_env.postman_environment.json

shifangfangdeMacBook-Pro:postman_test shifangfang$ git commit -m "postman_pro_order"

[master (root-commit) a5927a5] postman_pro_order

2 files changed, 5931 insertions(+)

create mode 100644 pro_env.postman_environment.json

create mode 100644 pro_env_order.postman_collection.json

shifangfangdeMacBook-Pro:postman_test shifangfang$ git remote add originhttps://github.com/herry-ff/postman_test.git

shifangfangdeMacBook-Pro:postman_test shifangfang$ git push -u origin master

Counting objects: 4, done.

Delta compression using up to 4 threads.

Compressing objects: 100% (4/4), done.

Writing objects: 100% (4/4), 13.63 KiB | 0 bytes/s, done.

Total 4 (delta 0), reused 0 (delta 0)

remote:

remote: Create a pull request for 'master' on GitHub by visiting:

remote:      https://github.com/herry-ff/postman_test/pull/new/master

remote:

To https://github.com/herry-ff/postman_test.git

* [new branch]      master -> master

Branch master set up to track remote branch master from origin.

shifangfangdeMacBook-Pro:postman_test shifangfang$

3、安装newman

第一步:安装nodejs,

参考文档:https://www.cnblogs.com/shiyunfront/p/7337783.html

      1)先安装brew,

命令行输入 /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"   回车(这里有提示目录不存在,要创建需要按return键,如果用的windows键盘,就是回车键)

      2)brew install node

第二步:在nodejs命令行安装newman,即命令行输入如下命令:

shifangfangdeMacBook-Pro:~ shifangfang$ npm install -g newman-reporter-html

npm WARN invalid config registry=""

npm WARN invalid config Must be a full url with 'http://'

/usr/local/lib

├── UNMET PEER DEPENDENCY newman@4

└── newman-reporter-html@1.0.2

npm WARN newman-reporter-html@1.0.2 requires a peer of newman@4 but none was installed.

PS、使用newman运行json脚本

参考文档https://github.com/postmanlabs/newman#configuring-reporters

run 脚本路径

-e 环境变量路径

-g 全局变量路径

--reporter-html-export 报告路径及名称

--export-globals 路径 执行完更新后的全局变量文件

--export-environment路径 执行完更新后的环境变量文件

比如:

shifangfangdeMacBook-Pro:~ shifangfang$ newman run /Users/shifangfang/Desktop/pro_env_order.postman_collection.json -e /Users/shifangfang/Desktop/pro_env.postman_environment.json --reporters html --reporter-html-export /Users/shifangfang/Desktop/result-order.html --export-environment /Users/shifangfang/Desktop/

4、jenkins创建freestyle job

PS:shell命令---html报告名称前最好加个编号,不然多次最新会一直覆盖看不到之前生成newman run /Users/Shared/Jenkins/Home/workspace/pro_env_order/pro_env_order.postman_collection.json -e /Users/Shared/Jenkins/Home/workspace/pro_env_order/pro_env.postman_environment.json --reporters html --reporter-html-export /Users/Shared/Jenkins/Home/workspace/pro_env_order/result-order$BUILD_NUMBER.html

4.1、构建

PS:执行构建任务发现报错,报错信息

/Users/Shared/Jenkins/tmp/jenkins5552974125428727684.sh: line 2: newman: command not found

Build step 'Execute shell' marked build as failure

参考:https://github.com/postmanlabs/newman/issues/778

解决办法:配置好newman环境变量


5、本地仓库变更上传到远程仓库,使用idea工具

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 131,763评论 18 138
  • Git 基础 基本原理 客户端并不是只提取最新版本的文件快照,而是把代码仓库完整的镜像下来。这样一来,任何一处协同...
    __silhouette阅读 15,398评论 5 147
  • This project was bootstrapped with Create React App. Belo...
    unspecx阅读 4,848评论 0 2
  • 《八太爷》是一部追逐英雄梦的悲剧。小说描绘了农民王二铁勇猛好胜,而又勤劳,是地里的好手,由于执着于不现实的英雄梦,...
    作家苦旅阅读 3,684评论 8 20
  • 自恋,生活在自己的世界里,觉得不符合自己的要求就起冲突,像个巨婴。 卓越强迫症,像个巨婴。 不行动就像一个巨婴一样...
    Uncle_Ma阅读 315评论 0 0
  • 从开始读《白鹿原》到把这本书看完,差不多花了2个多月的时间吧。这本书总体而言写的不错,看完这本书也还是有很多感触的...
    双木_ly阅读 202评论 0 0
  • 即墨染儿阅读 145评论 0 0