在Ubuntu系统上使用Postman进行自动化测试,可以按照以下步骤进行:
sudo apt update
sudo apt upgrade
sudo apt install snapd
sudo snap install postman
postman
wget https://dl.pstmn.io/download/latest/linux64 -O postman.tar.gz
sudo tar -xzf postman.tar.gz -C /opt/
sudo ln -s /opt/Postman/Postman /usr/local/bin/postman
sudo nano /usr/share/applications/postman.desktop
在文件中添加以下内容:[Desktop Entry]
Encoding=UTF-8
Name=Postman
Exec=/opt/Postman/Postman
Icon=/opt/Postman/app/resources/app/assets/icon.png
Terminal=false
Type=Application
Categories=Development;
保存并退出编辑器,然后赋予快捷方式可执行权限:sudo chmod +x /usr/share/applications/postman.desktop
将快捷方式复制到桌面。pm.test("Status code is 200", function() {
pm.response.to.have.status(200);
});
pm.test("Response body contains expected value", function() {
pm.expect(pm.response.json().key).to.eql("expectedvalue");
});
newman collection export collection.json
newman run collection.json --environment environment.json
name: RUNPostmanAPITest
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
RUN-Postman-API-Test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18.x]
steps:
- uses: actions/checkout@v3
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: Install newman
run: npm install -g newman
- name: Run Postman tests
run: newman run "your_postman_collection.json" --reporters cli,junit --reporter-junit-export report.xml
- name: Publish test results
uses: actions/upload-artifact@v2
with:
name: postman-test-results
path: report.xml
通过以上步骤,您可以在Ubuntu系统中成功使用Postman进行API自动化测试,并将测试集成到CI/CD流程中,提高测试效率和准确性。