Hello
New to Postman but enjoying the learning journey a lot.
I have two queries where the first one âBeginQueryâ returns a token that is next used in âEndQueryâ. I have not been able to have EndQuery wait for the token (which set in BeginQueryâs test step ) until EndQuery is sent. Without a token the EndQuery fails.
If I hardcode a five second timeout in EndQueryšs pre-request script I can run the the collection just fine. But I would much rather have a condition that waits for a collection variable to be set before running EndQuery. I will build many other tests for other endpoints what may wait longer or shorter. It also make sense to be able to set a max timeout if possible.
I have tried some if else statements with timeouts and a while loop (that went infinite loop on me). but so far no success. I have tried to illustrate the steps below.
BeginQuery
Pre-request script:
none
Query:
send some known data
Test:
run various tests
set a collection variable for the token returned from the response
pm.collectionVariables.set(âtokenâ, $(âBeginStrategyResult > Tokenâ).text());`
(I have checked that the collectionvariable "token"is in fact created at this step and later unset after EndQuery test step)
EndQuery
Pre-request script:
Wait until the collection variable âtokenâ is set. This is where I run into the problem
pm.collectionVariables.has("token")
Query:
Send token in request
Test:
run various tests
clear the token variable
pm.collectionVariables.unset("token");
I appreciate any help the community can offer. Cheers!