I am trying to run the same request multiple times based on a JSON array. The issue I have is that it only executes the request once, like it’s ignoring the setNextRequest. I’ve seen a bunch of posts similar to this issue, but none of the suggestions seem to resolve my issue. I am running it via a Collection runner and it is not reacting as I expect. I have the log statement and it is displaying each iteration (0 and 1), but the “get vehicle” request only occurs once instead of twice as I would expect and it has the property value of “truck” so its only getting the value of the last item in the array. Any suggestions would be appreciated.
Here is my code that is in the Pre-Request Script:
let attributeArray = [{
"cars": '{"type": "string"}'
},
{
"trucks": '{"type": "string"}'
}
];
for (var i = 0; i < attributeArray.length; i++)
{
var obj = attributeArray[i];
for (var property in obj)
{
var propertyType = obj[property];
pm.collectionVariables.set("attributeProperty", property);
pm.collectionVariables.set("attributePropertyType", propertyType);
postman.setNextRequest("get vehicle");
console.log(i);
}
}