Body contains numerous keys - but I am only testing two of the keys.
Key1 and Key2.
Key1 can be [a,b,c,d].
Key2 can be {a:[1,2,3], b:[4,5,6], c:[7,8,9], d:[10,11,12]}
I had no issues passing values for each test when one key is involved.
In my pre-request tab:
let keyObj = pm.collectionVariables.get("keyObj");
keyObj = {'a':[1,2,3], 'b':[4,5,6], 'c':[7,8,9], 'd':[10,11,12]
}
for (let i in keyObj ){
let key1 = i;
pm.collectionVariables.set("key1",key1);
let keyVals = keyObj[key1];
for (let j=0; j < keyVals.length; j++){
let tempVal = keyVals[j];
console.log(key1,tempVal);
pm.collectionVariables.set("key2",tempVal);
//i want the request to be sent here!
}
delete keyObj[i];
}
And in my Test tab:
let keyObj = pm.collectionVariables.get("keyObj");
if (Object.keys(keyObj).length == 0){
postman.setNextRequest(null);}
else {
postman.setNextRequest(pm.info.requestName)};
//assertions below
The problem is it’s only sending the request ONCE for key1 = 'd' and key2 = 12
Is there any way to kick off the request as soon as I set the variables? Please feel free to make suggestions on how I’m looping through the data.
Thank you.