Postman 如何通过POST请求调用下一个GET请求,POST请求使用;setNextRequest“;
以下是场景: 给定我有多个输入数据(在请求前脚本中设置)用于请求后 当返回ID时 然后使用POST请求->测试中的“setNextRequest”命令断言通过GET请求传递ID的详细信息 注意:测试从collection runner运行Postman 如何通过POST请求调用下一个GET请求,POST请求使用;setNextRequest“;,postman,Postman,以下是场景: 给定我有多个输入数据(在请求前脚本中设置)用于请求后 当返回ID时 然后使用POST请求->测试中的“setNextRequest”命令断言通过GET请求传递ID的详细信息 注意:测试从collection runner运行 Request Body: { "name": "{{client_name}}", "email": "{{client_email}}" } Pre-request_script: pm.environment.set("client_n
Request Body:
{
"name": "{{client_name}}",
"email": "{{client_email}}"
}
Pre-request_script:
pm.environment.set("client_name","Client_" + new Date().getTime());
pm.environment.set("client_email", "Client_" + Math.random().toString(36).substr(2, 9) + "@abc.com");
Tests:
var jsonData = JSON.parse(responseBody);
if(jsonData.id){
pm.environment.set("client-admin-client-id", jsonData.id);
pm.sendRequest("GetClient By ID", function (err, response) {
console.log(JSON.parse(response.json()));
});
}else{
postman.setNextRequest(null);
}```
实际行为:
它无法访问ID为的GET URL
预期行为:
我需要从collection runner自动断言详细信息
Request Body:
{
"name": "{{client_name}}",
"email": "{{client_email}}"
}
Pre-request_script:
pm.environment.set("client_name","Client_" + new Date().getTime());
pm.environment.set("client_email", "Client_" + Math.random().toString(36).substr(2, 9) + "@abc.com");
Tests:
var jsonData = JSON.parse(responseBody);
if(jsonData.id){
pm.environment.set("client-admin-client-id", jsonData.id);
pm.sendRequest("GetClient By ID", function (err, response) {
console.log(JSON.parse(response.json()));
});
}else{
postman.setNextRequest(null);
}```
到目前为止你试过什么?什么不起作用?给我们看预请求代码?如果您使用的是
setNextRequest
,则此操作仅在集合运行程序中有效。更新了说明有人可以帮助我吗?您没有任何关于pm的测试。除了
语句之外,您的断言是什么?什么是if
语句条件检查,只是为了查看id
属性是否存在?在if
块中有一个pm.sendRequest()
,这是干什么的?这与setNextRequest()
不同。