在Ubuntu上使用Postman进行自动化测试的步骤如下:
sudo snap install postman --classic
wget -qO - https://dl.postman.co/postman.gpg | sudo apt-key add -
echo "deb https://dl.postman.co/debian $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/postman.list
sudo apt update && sudo apt install postman
sudo apt install flatpak
flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo
flatpak install flathub com.postman.Postman
安装后可通过终端输入postman
启动应用。{{变量名}}
在请求中使用。// 验证状态码为200
pm.test("Status code is 200", function() {
pm.response.to.have.status(200);
});
// 验证响应体包含特定字段
pm.test("Response has required fields", function() {
const jsonData = pm.response.json();
pm.expect(jsonData).to.have.property("success");
});
支持变量引用(如pm.environment.get("token")
)、数据参数化(CSV/JSON文件)等。npm install -g newman
newman run collection.json -e environment.json --reporters cli,html
支持生成HTML报告或集成到CI/CD流程。pm.iterationData.get("变量名")
引用。pm.environment.set()
和pm.environment.get()
动态切换环境变量。参考来源: