Postman在CentOS中的配置方法
Postman在CentOS中的配置主要分為應用程序安裝(桌面端)和命令行工具配置(Newman)兩部分,以下是詳細步驟:
.tar.gz格式)下載;或使用wget命令直接下載最新版:wget https://dl.pstmn.io/download/latest/linux64 -O postman.tar.gz/usr/local/postman(需管理員權限):sudo mkdir -p /usr/local/postmansudo tar -zxf postman.tar.gz --strip-components=1 -C /usr/local/postman//usr/bin:sudo ln -s /usr/local/postman/Postman/Postman /usr/bin/postmansudo touch /usr/share/applications/postman.desktop[Desktop Entry]
Encoding=UTF-8
Name=Postman
GenericName=API Tools
Comment=Postman API測試工具
Exec=/usr/bin/postman
Terminal=false
MimeType=text/plain
Icon=/usr/local/postman/app/resources/app/assets/icon.png
StartupNotify=true
Categories=Development;
賦予執行權限:sudo chmod +x /usr/share/applications/postman.desktoppostman,或在應用菜單中找到Postman圖標啟動。若系統已安裝Snap(未安裝則執行sudo yum install snapd && sudo systemctl enable --now snapd.socket),可直接通過Snap安裝Postman:
sudo snap install postman --classic
安裝完成后,通過postman命令啟動應用程序。
Postman官方提供了YUM倉庫支持,步驟如下:
sudo rpm -Uvh https://dl.pstmn.io/download/latest/linux/x64/yum/yum.reposudo yum install postmanpostmanNewman是Postman的命令行版本,用于自動化運行API測試集合,適合CI/CD流程。
Newman依賴Node.js環境,通過YUM安裝:
sudo yum install -y nodejs npm
驗證安裝:node -v(顯示版本號)、npm -v(顯示版本號)。
使用npm安裝Newman(需管理員權限):
sudo npm install -g newman
驗證安裝:newman --version(顯示版本號)。
collection.json)。newman run /path/to/collection.jsonenvironment.json),并通過-e參數指定:newman run /path/to/collection.json -e /path/to/environment.jsonrun_postman.sh),內容如下:#!/bin/bash
COLLECTION_FILE="/path/to/collection.json"
ENVIRONMENT_FILE="/path/to/environment.json"
newman run "$COLLECTION_FILE" -e "$ENVIRONMENT_FILE"
賦予執行權限:chmod +x run_postman.sh,運行腳本:./run_postman.sh。/etc/systemd/system/postman.service),內容如下:[Unit]
Description=Newman Postman Collection Runner
After=network.target
[Service]
ExecStart=/usr/local/bin/newman run /path/to/collection.json -e /path/to/environment.json
Restart=always
User=your_username
[Install]
WantedBy=multi-user.target
啟用并啟動服務:sudo systemctl daemon-reloadsudo systemctl enable postman.servicesudo systemctl start postman.servicesudo systemctl status postman.service。baseUrl=https://api.example.com、apiKey=123456),點擊“Save”。{{variable_name}}引用(如{{baseUrl}}/users)。pm.test("Status code is 200", function () {
pm.response.to.have.status(200);
});
pm.test("Response contains user data", function () {
const jsonData = pm.response.json();
pm.expect(jsonData).to.have.property("id");
});
以上步驟覆蓋了Postman在CentOS中的主要配置場景,可根據需求選擇桌面端或命令行工具使用。