I am trying to find a proper way in postman to iterate between 2 requests until certain criteria is matched.
I have a GET /categories request where it gives you bunch of categories and I have another request Get /PLP. However in certain cases PLP get empty list making tests to failed because categories we store in variable is empty.
The thing I was trying was on /GET PLP requests, in pre-requisite script I am sending GET PLP request and checking if it is empty or not, if its empty I was setting postman.setNextRequest("Categories") so that it loops around until PLP is not empty. However this is not working for me. Has anyone have any idea how to solve it or have different approach. Below is my prerequisite script
var jsonData;
pm.sendRequest({
url: pm.environment.get('url') + "categories=" + pm.environment.get('subCategoryId'),
method: 'GET',
header: {
'content-type': 'application/json',
}
}, function (err, response) {
if (err) throw new Error(err);
var jsonData = response.json().numberOfItems;
console.log(jsonData)
});
if (jsonData == 0) {
postman.setNextRequest("Categories");
}