This text will be hiddenI have the following pre-request script:
console.log(“Entering test pre-request script - (” + new Date().toISOString() + “)”);
var sleep = eval(pm.globals.get(“sleep”));
// Generate the random vin
getRandomVin = eval(pm.globals.get(“getRandomVin”));
getRandomVin();
console.log(“Returned from getRandomVin() - (” + new Date().toISOString() + “)”);
sleep(5);
console.log(“Sleep completed - (” + new Date().toISOString() + “)”);
var vin = pm.globals.get(“Testvin”);
console.log(“Vin from global was - (” + new Date().toISOString() + "): " + vin);
console.log(“Exiting test pre-request script- (” + new Date().toISOString() + “)”);
The getRandomVinFunction() sends a request to obtain a random automobile vin. The function populates the Testvin global variable with the value. I expected that after calling the function and waiting 5 seconds, that the global variable would be populated by the asynchronous SendRequset code. The log shows that the sendRequest activity occurs after the completion of the pre-request script.
Is there a way to make this behave differently? I don’t think it is unreasonable to want to use the result of a called function later in the same script.