Hi all, i really need your help guys to figure this out i new to scripting parts
My question:
How to Loop Variables from array lists to request body.
I’ve already tried:
pre-request
var status_list = [""," "," UPCOMING","UPCOMING ", 123456, "123asd", true, "UPCOMING"];
var status;
var count =pm.collectionVariables.get("count");
if(count < status_list.length) {
status = status_list[count];
console.log("status",status);
count++;
}
else if(count >= status_list.length){
console.log("else")
count=1;
}
pm.collectionVariables.set("status_list", status_list);
pm.collectionVariables.set("status",status);
console.log("final_status",status);
console.log("count",count);
pm.collectionVariables.set("count", count);
test
const status_list = pm.collectionVariables.get("status_list");
const status = pm.collectionVariables.get("status");
const count = pm.collectionVariables.get("count");
if (status && status_list.length > count && pm.response.code === 400){
console.log("test_line",)
pm.test('Check Status Code is 400');
postman.setNextRequest("Loop Post Parameter");
} else if(status && status_list.length == count) {
pm.test('Check status should be UPCOMING', () => {
if(pm.response.code === 200) {
var jsonData = pm.response.json().data.items.status;
pm.expect(jsonData).to.eql("UPCOMING");
}
});
}