Reputation: 47
I have Request A and Request B which I have to test in the Postman Test Condition for testing these API is that Success of Request A is depended on the response of the Request B When the request A is hit the response from the Request B send the initial value as 2 for attribute 2 then after 30 second the response of value change to 2.1 which is success of test
Request A
Request B
Response B
{
Attribute 1: Value 1
Attribute 2: Value 2 Value 2.1
Attribute 3: Value 3
}
Code written in Postman Test is below
pm.test("Check Success Status",function(){
let i =1;
do{
pm.sendRequest("Request B",function(err,res){
var JsonData=res.json();
if(JsonData.attribute2=="Value 2.1"){
{
break;
}else{
setTimeout(2000);
}
})
i++;
}while(i<5)
})
Please let me know if I have implemented the correct logic or is there any other way to do that ?
Upvotes: 0
Views: 386
Reputation: 750
I would trigger the dependent request inside the body of the previous request like this:
pm.sendRequest(postRequest, (error, response) => {
console.log(error ? error : response.json());
console.log("First")
pm.sendRequest(postRequest, (error, response) => {
console.log(error ? error : response.json());
console.log("Second")
});
});
Upvotes: 1