美文网首页
Postman+Newman+Jenkins实现webapi接口

Postman+Newman+Jenkins实现webapi接口

作者: 多夏_zoey | 来源:发表于2018-11-05 15:04 被阅读252次

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工具

相关文章

网友评论

      本文标题:Postman+Newman+Jenkins实现webapi接口

      本文链接:https://www.haomeiwen.com/subject/ximycftx.html