51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

查看: 2355|回复: 1
打印 上一主题 下一主题

[转贴] Postman+Newman+Jenkins实现webapi接口回归测试

[复制链接]

该用户从未签到

跳转到指定楼层
1#
发表于 2019-4-10 16:34:52 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
1、在postman上创建项目
2、上传本地源码到远程仓库
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,
      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脚本


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

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




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







本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?(注-册)加入51Testing

x
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏
回复

使用道具 举报

本版积分规则

关闭

站长推荐上一条 /1 下一条

小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

GMT+8, 2024-4-26 15:29 , Processed in 0.064140 second(s), 25 queries .

Powered by Discuz! X3.2

© 2001-2024 Comsenz Inc.

快速回复 返回顶部 返回列表