Postman+Newman+Jenkins實現webapi接口回歸測試

1、在postman上創建項目

postman入門使用教程參見http://www.lxweimin.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閱讀 134,991評論 19 139
  • Git 基礎 基本原理 客戶端并不是只提取最新版本的文件快照,而是把代碼倉庫完整的鏡像下來。這樣一來,任何一處協同...
    __silhouette閱讀 15,958評論 5 147
  • This project was bootstrapped with Create React App. Belo...
    unspecx閱讀 5,231評論 0 2
  • 《八太爺》是一部追逐英雄夢的悲劇。小說描繪了農民王二鐵勇猛好勝,而又勤勞,是地里的好手,由于執著于不現實的英雄夢,...
    作家苦旅閱讀 5,791評論 8 20
  • 自戀,生活在自己的世界里,覺得不符合自己的要求就起沖突,像個巨嬰。 卓越強迫癥,像個巨嬰。 不行動就像一個巨嬰一樣...
    Uncle_Ma閱讀 500評論 0 0