为了保存 postman API 调用的响应,我使用 newman run 执行 Postman 集合。
集合运行时使用
newman run C:\TasteBud\NewMan\JSON-Order_collection.json --env-var unique_order_id=OD-06-07-I2Q5-JYRY5ARPN --environment C:\TasteBud\NewMan\EnvironmentJSON.json
但是,当我将同一个集合作为 javascript 或 nodejs 脚本的一部分运行时。
node writeToFile.js
当节点 "1⠄ JSONError in test-script " 引用附加图像时,它会抛出错误。我需要将登录请求生成的身份验证令牌传递给后续请求。所以我在“测试”中有变量赋值。
let response = pm.response.json();
pm.environment.set("auth_token", response.data.auth_token);
console.log(pm.response.json().data.auth_token);
为什么我不能进行“测试”?如果没有,那么如何为后续 API 调用传递/设置这些环境变量?
writeToFile.js 中的代码在这里。 writeToFile.js