我有一个包含 3 个请求(A、B、C)的邮递员集合,并且我有 3 个不同的环境:“dev”、“test”、“uat”。 我想创建一个 Run,它将针对 3 个不同的环境运行集合中的所有 3 个请求。所以有效运行将是:
env:dev, request A
env:dev, request B
env:dev, request C
env:test, request A
env:test, request B
env:test, request C
env:uat, request A
env:uat, request B
env:uat, request C
在Postman中有没有简单的方法来实现它?
Newman将解答您的问题。
使用环境运行 newman
newman run your.postman_collection.json -e dev.postman_environment.json
newman run your.postman_collection.json -e test.postman_environment.json
newman run your.postman_collection.json -e uat.postman_environment.json
演示 REST API
https://freetestapi.com/apis/animals
通过[动物名称]查询获取动物 https://freetestapi.com/api/v1/animals?search=[动物名称]
dev environment
test environment
uat environment
request A
https://freetestapi.com/api/v1/animals?search={{request_A}}
Tests
选项卡
var jsonData = JSON.parse(responseBody);
console.log(jsonData[0].name);
pm.expect(jsonData[0].name).to.eql(pm.environment.get("request_A"));
request B
https://freetestapi.com/api/v1/animals?search={{request_B}}
Tests
选项卡
var jsonData = JSON.parse(responseBody);
console.log(jsonData[0].name);
pm.expect(jsonData[0].name).to.eql(pm.environment.get("request_B"));
request C
https://freetestapi.com/api/v1/animals?search={{request_C}}
Tests
选项卡
var jsonData = JSON.parse(responseBody);
console.log(jsonData[0].name);
pm.expect(jsonData[0].name).to.eql(pm.environment.get("request_C"));
Export collection
将另存为 1-demo.postman_collection.json
Export environment
将另存为 dev.postman_environment.json
其他两个环境 将另存为
test.postman_environment.json
将另存为 uat.postman_environment.json
newman
另存为
run.sh
newman run 1-demo.postman_collection.json -e dev.postman_environment.json
newman run 1-demo.postman_collection.json -e test.postman_environment.json
newman run 1-demo.postman_collection.json -e uat.postman_environment.json
./run.sh