[英]How to use variable from one request in another request test body in postman test body?
I want to execute 3 requests (api1, api2 and api3) one after the other.我想一个接一个地执行 3 个请求(api1、api2 和 api3)。 I want to make api3 request dependent on values(type:int) of api1 and api2.
我想让 api3 请求依赖于 api1 和 api2 的值(类型:int)。
In api1 request test body:在 api1 请求测试正文中:
var data = pm.response.json();
var count1 = data.length;
In api2 request test body:在 api2 请求测试正文中:
var data = pm.response.json();
var count2 = data.length;
if(count1 == 0 && count2 == 0){
postman.setNextRequest(null);
}
Doing this, it throws a "ReferenceError: count1 is not defined"
after firing the api2 request.这样做,它会在触发 api2 请求后抛出
"ReferenceError: count1 is not defined"
。
I don't want to execute the request api3 if both the count values (count1 and count2) are 0. Please help!如果计数值(count1 和 count2)都为 0,我不想执行请求 api3。请帮忙!
In the test of the api1 request, you need to store the value of count1 in an environment variable: pm.environment.set("count1", count1));
在api1请求的测试中,需要将count1的值保存在一个环境变量中:
pm.environment.set("count1", count1));
Then use that environment variable in the test of api2: count1 = pm.environment.get("count1");
然后在 api2 的测试中使用该环境变量:
count1 = pm.environment.get("count1");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.