Hi
Sorry for my title, very hard to explain without code or an example
From the beginning, my goal is to run a while
loop max 3 minutes while the condition is true.
All while loop try crushed, so I did with the if
statement.
Before adding a time limit, all scripts were working fine, but when I added a time limit, I realized
I was doing something very silly, and I don’t know how to solve that.
At the pre-request tab, I assign startTime
with a Date.Now().
const startTime = Date.now();
pm.environment.set("startTime", startTime);
At the post-response tab, I am checking the time difference from startTime and now.
Funny thing, always startTime is dependent on DateNow(), and whenever Ioop runs again, startTime updates. And this is expected.
let startTime = pm.variables.get('startTime')
let currentTime = Date.now();
let elapsedTime = currentTime - startTime;
let timeLimit = 180000; // 3 min = 180 second = 180000 ms
if (elapsedTime < timeLimit) {
if (MY_CONDITION) {
pm.execution.setNextRequest(pm.info.requestName);
} else {
pm.execution.setNextRequest();
}
} else {
pm.execution.setNextRequest();
}
P.S. if(elapsedTime < timeLimit && MY_CONDITION)
could be better, but my focus for solving the time issue first
so…
Whenever I run the collection, startTIme updating for each iteration,
I wanna keep startTime from the beginning for keeping track of time-should never update during loop :: let elapsedTime = currentTime - startTime;
startTIme should be the same all the time
Any help appreciated, if there is any other way to run a loop for 3 min, that’s OK too,
I am open to ideas.
thanks