在Azure DevOps Pipeline上运行Newman时遇到一个奇怪的问题。这是正在发生的事情的摘要:
Post
Test A
POST XXXXX [500 Internal Server Error, 442B, 8.6s]
1⠄ JSONError in test-script
Test A Copy
POST XXX [200 OK, 692B, 8.9s]
√ Is Successful
√ Status Code
√ Status Message
---
# failure detail
1. JSONError
No data, empty input at 1:1
^
at test-script
确切的测试似乎无关紧要,如果是第一个测试,它总是会失败。为了证明这一点,我复制了失败的测试,以便现在有了
突然,“测试副本”起作用了。因此,这不是测试的内容,而是要测试的第一个测试。所有这些测试都是POST的
测试A内容:
var jsonData = pm.response.json();
pm.test("Is Successful", function() {
pm.expect(jsonData.IsSuccessful).to.be.true;
})
pm.test("Status Code", function() {
pm.response.to.have.status(200);
})
pm.test("Status Message", function() {
pm.expect(jsonData.StatusMessage).eql("Document insert successful.");
})
没有什么太花哨的了,那为什么在第一次运行(测试A)而不是第二次(测试A副本)时会失败呢?不管是哪个测试,如果我先运行TEST B,那将是失败的。
似乎第一个请求是唤醒服务器的内容,然后一切正常。
答案 0 :(得分:2)
我在Postman中运行Azure Devops Rest API,并使用export json文件在Pipeline中运行Postman测试
这是我在azure管道中运行newman的步骤,您可以参考它们。
第一步:在PostMan中导出收藏集。
第二步:将Json文件(例如APITEST.postman_collection.json)上传到Azure Repo。
第3步:创建管道并添加install Newman step
,run Postman test step
。
示例:
steps:
- script: |
npm install -g newman@5.1.2
workingDirectory: '$(System.DefaultWorkingDirectory)'
displayName: 'Command Line Script'
- script: 'newman run TEST.postman_collection.json --reporters cli,junit --reporter-junit-export Results\junitReport.xml '
workingDirectory: '$(build.sourcesdirectory)'
displayName: 'Command Line Script
或与Newman the cli Companion for Postman
任务一起运行(这是扩展任务)。
steps:
- script: |
npm install -g newman@4.6.1
workingDirectory: '$(System.DefaultWorkingDirectory)'
displayName: 'Command Line Script'
- task: NewmanPostman@4
displayName: 'Newman - Postman'
inputs:
collectionFileSource: 'TEST.postman_collection.json'
environmentSourceType: none
ignoreRedirect: false
bail: false
sslInsecure: false
htmlExtraDarkTheme: false
htmlExtraLogs: false
htmlExtraTestPaging: false
第四步:运行管道,它可以显示与邮递员相同的api结果。