This issue I am facing is that the code should run 2 iterations, but will only run 1 at a time. The first time I send the request, it runs the first iteration. If I send the request again, it will then run the second iteration. I have looked at the docs and existing question around this issue, and I believe that the code I have created follows the basic guidelines. I am wondering if the fact that I am getting values from env variables is having some effect. The token vars should really be env vars, but if that is the problem I guess I can change them to something else. I have also tried altering the “level” of other variables, since I think I may have had those wrong at some point. I have tried setting the bearerToken variable at all different variable levels (started at global, moved to env, and now finally to collection, but it hasn’t made 1 bit of difference). I thought for sure the problem was that the bearerTokenList variable had to be a collection level var, but that didn’t help.
Pre-request script
let qaMortToken = pm.environment.get("bearerToken_QA_Mort_Kirstin_Non_SSO");
let kirstinTestToken = pm.environment.get("bearerToken_Kirstin_Test_KW");
let bearerTokenList = pm.collectionVariables.get("bearerTokenList");
console.log("token list before: " +bearerTokenList )
if(!bearerTokenList || bearerTokenList.length == 0) {
bearerTokenList = [qaMortToken, kirstinTestToken];
console.log("token list after: " +bearerTokenList )
console.log("token list length: " +bearerTokenList.length )
}
let currentToken = bearerTokenList.shift();
pm.collectionVariables.set("bearerToken", currentToken)
pm.collectionVariables.set("bearerTokenList", bearerTokenList);
console.log("current token:" +currentToken)
console.log("prerequest token list: " +bearerTokenList)
Test script:
let bearerTokenList = pm.collectionVariables.get("bearerTokenList");
console.log("test token list: " +bearerTokenList);
console.log("length: " +bearerTokenList.length)
console.log(bearerTokenList)
if(bearerTokenList && bearerTokenList.length > 0) {
console.log("in if block")
postman.setNextRequest("Create Child Org");
} else {
console.log("in else block")
postman.setNextRequest(null)
}
pm.test("Status code is 200", function () {
pm.response.to.have.status(200);
});
Request 1 console log (sanitized):
token list before:
token list after: token1, token2
token list length: 2
current token:token1
prerequest token list: token2
POST https://api/organizations/child
400
397 ms
test token list: token2
length: 1
(1) [“token2”]
in if block
Request 2 console log (sanitized):
token list before: token2
current token:token2
prerequest token list:
POST https://api/organizations/child
403
306 ms
test token list:
length: 0
in else block
Using Postman for Windows V 10.13.5 OS Platform win32 10.0.19045