简体   繁体   English

如何在邮递员测试主体的另一个请求测试主体中使用来自一个请求的变量?

[英]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.

相关问题 邮递员:如何在请求正文中使用环境变量 - Postman: How to use environment variables in Request Body 邮递员测试获取名为“电子邮件”的请求正文问题 - Postman Test getting request body named "email" problem 如何在 Express 中将请求正文的数据从一条路由移动到另一条路由 - How to move data of request body from one route to another in Express 如何在一个地方保存邮递员请求正文并在运行时通过 - How to save a postman request body in one place and pass when run 邮递员测试顺利进行,但Ajax出错“缺少所需的请求正文” - Postman test goes well but ajax get wrong “Required request body is missing” 如何在请求正文中传递变量? - How to pass variable in request body? 在 Postman 中发送带有正文的请求 - Sending request with text body in Postman Express无法识别来自Postman的正确请求正文 - Express not recognizing correct request body from Postman on PUT request 在Postman中,我如何从“获取请求”中获取响应正文,并将其放入经过细微更改的PUT请求中 - In Postman, how do I take a response body from a Get Request, and put it in a PUT request with minor changes 为 Postman 中的每个请求测试设置可访问的测试集合变量 - Set a test collection variable accessible for each request test in Postman
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM