Postman 针对不同环境运行集合

问题描述 投票:0回答:1

我有一个包含 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中有没有简单的方法来实现它?

environment-variables postman postman-collection-runner postman-collection
1个回答
0
投票

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/test/uat)

dev environment

test environment

uat environment

设置三个请求(dev/test/uat)

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

通过 bash 在三个环境中运行
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

在 git bash 中运行它

./run.sh

结果

© www.soinside.com 2019 - 2024. All rights reserved.