Postman (newman) 到 Github Actions 上的一些小記錄
前陣子遇到一個需求,團隊的 API 測試放在 postman 上,所以想要試試讓 Postman 放在 Github Actions 上面執行。當時花蠻多時間的,紀錄一些過程。
Postman (newman) 到 Github Actions 上的一些小記錄
前陣子遇到一個需求,團隊的 API 測試放在 postman 上,所以想要試試讓 Postman 放在 Github Actions 上面執行。當時花蠻多時間的,紀錄一些過程。
- 在 Postman CLI 和 Newman 做選擇 Postman CLI 是官方提供的 CLI 套件,而 Newman 是社群維護的。 一開始我先用了 Postman CLI。 畢竟是官方提供,整合做得很好。有些 API 測試時需要上傳的檔案,有在 postman 上傳過並儲存在 postman cloud 的話,都可以直接使用。而測試結果直接顯示在 Postman 的 Runs 裡面—— 沒想到這竟然是個缺點,它的 reporter 不能自訂,唯一的 report 就是要去剛剛提到的 Runs 裡面看,不然就是直接來自執行時的 CLI ⋯⋯(來源參考 https://community.postman.com/t/postman-cli-reporting/66763)
所以就因為 Newman 可以自訂 reporter,直接選了 Newman XDDDD
-
上傳檔案的測試 用了 newman 也不是就一帆風順。 比方上傳檔案的話有點麻煩,要匯出 collection 之後填上檔案路徑。 這比起用 Postman CLI 麻煩多了。原先在 postman 改完 collection 裡的任何部分之後執行就能生效。但為了讓 Newman 上傳檔案,用匯出的 collection 就沒辦法了QQ
-
執行失敗的 log 當時還有個痛點,就是失敗時沒有 response 的 log ⋯⋯ 可以做到的方法大致上是在每一個 API 的 post-script 加上紀錄,比方:
pm.test("Response status code is 200", function () {
if (pm.response.code !== 200) {
throw new Error(`Response Code: ${pm.response.code} | Response Body: ${pm.response.text()} | Request Body: ${JSON.stringify(pm.request.body)}`);
}
pm.response.to.have.status(200);
});;
總之成功在 Actions 上跑了一段時間,不過後來還是決定換成自己寫的 API 框架了。謹此紀念沒跑多久的 Postman 上 Github Actions 經歷XDD
메타데이터
- post_id
- bd96b59b5bb8
- slug
- postman-newman-到-github-actions-上的一些小記錄-bd96b59b5bb8
- url
- https://medium.com/@goescat/postman-newman-%E5%88%B0-github-actions-%E4%B8%8A%E7%9A%84%E4%B8%80%E4%BA%9B%E5%B0%8F%E8%A8%98%E9%8C%84-bd96b59b5bb8
- canonical_url
- https://medium.com/@goescat/postman-newman-%E5%88%B0-github-actions-%E4%B8%8A%E7%9A%84%E4%B8%80%E4%BA%9B%E5%B0%8F%E8%A8%98%E9%8C%84-bd96b59b5bb8
- author_url
- https://medium.com/@goescat
- status
- ok
- fetched_at
- 2026-07-21 23:30:11