如何在 POSTMAN - AUTOMATION 中将标记值从一个集合传递到另一个集合新人

How to pass token value from one collection to another collection in POSTMAN - AUTOMATION | NEWMAN

我想使用 POSTMAN Collections API & NEWMAN 自动化我的单元测试用例。 我创建了两个测试用例,它们按预期工作。从 POSTMAN 导出集合后,我正在通过 NEWMAN 生成测试报告。

但是有一些 API 对另一个有一些依赖,意味着需要在参数中传递一个唯一的 ID,它来自另一个 API 调用。那么如何在 JSON.

中传递这些参数值

想在我的第二个 API call/second 测试用例中通过 costID

</p> <pre><code>{ "variables": [], "info": { "name": "UNIT TEST", "_postman_id": "e518f4c6-8cd0-2484-aff3-2f2b288f938e", "description": "", "schema": "https://schema.getpostman.com/json/collection/v2.0.0/collection.json" }, "item": [ { "name": "Price Testing", "description": "", "item": [ { "name": "PDP", "event": [ { "listen": "test", "script": { "type": "text/javascript", "exec": [ "var jsonData = JSON.parse(responseBody);", "var keyexist = \"YES\";", "var key = \"**costID**\" in jsonData ? \"YES\" : \"NO\";", "tests[\"costIDEXIST\"] = key === keyexist;" "" ] } } ], "request": { "url": { raw": "my api url1", "protocol": "https", "host": [ "www", "test", "com" ], "path": [ "jio", "v4", "l232" ], "query": [ { "key": "ispwa", "value": "true", "equals": true, "description": "" } ], "variable": [] }, "method": "GET", "header": [], "body": {}, "description": "" }, "response": [] } ] }, { "name": "TEST KEY CHECK", "description": "", "item": [ { "name": "kEY EXIST OR NOT", "event": [ { "listen": "test", "script": { "type": "text/javascript", "exec": [ "var jsonData = JSON.parse(responseBody);", "var keyexist = \"YES\";", "var key = \"ishEligible\" in jsonData ? \"YES\" : \"NO\";", "tests[\"ishEligible EXIST\"] = key === keyexist;" ] } } ], "request": { "url": { "raw": "my api url2", "host": [ "TEST", "com" ], "path": [ "jio", "v4", "l232" ], "query": [ { "key": "**costID**", "value": "true", "equals": true, "description": "" } ], "variable": [] }, "method": "GET", "header": [], "body": {}, "description": "" }, "response": [] } ] } ] }

是的,我通过在环境变量中设置 costID 得到了一个解决方案。这样我就可以在后续的 API 调用中使用该 costID。 postman.setEnvironmentVariable(\"costID \",jsonData.costID);

使用

pm.collectionVariables.set("variable_key","variable_value");
而不是

pm.environment.set("variable_key", "variable_value");