Post & pre flow level scripts are crucial when running tests? Flows really need to mimic the feature set of a collection
I would like to add a script that automatically requests a new access token, if a flow request returns a 401. I can do this at the collection level, no problem, but I cannot see anything in flows that can replicate this behavior?
I would also like a proper report returned, exactly the same as I see, at the end of a collection runner event. I would also like to export the results.
The reason I need to use a flow is that I want my collection folders/requests to be in alphabetical order, and not duplicated. Any requests that are used for housekeeping tasks, I can hide away in a folder called housekeeping. For instance, I might use the API to create two new folders, but obviously I don’t want hundreds of dummy folders to accumulate on our server, so I would like to use the flow to delete these folders with duplicated delete requests [different folder IDs]
But I don’t necessarily want to see these requests front & centre, in my collection. I would like my collection to act more like a library that syncs with our API documentation.
But flows need to be up to the task, which I don’t believe they are yet?
Please could you consider adding these features.
Summary:
- Post & pre flow level scripts
- Post & pre flow folder level scripts
- Post & pre flow action block level scripts
- Scripts need to be able to access other action request blocks and environment variables, so that we can read and write to the environment
- Flow runner reports
- Flow runner report export
HTTP Request blocks in Flows MUST execute Pre-request and Post-response scripts attached to the requests, just like Collection Runner does.
Without this, Flows cannot be used for real-world API testing.
At point 3, I would like to emulate something like this:
// Exclude login folder from auth retry logic
if (pm.info.requestName === "startSession" || pm.info.requestName.includes("login") || pm.info.requestName.includes("no auth required")) {
// Skip auth retry for login-related requests
return;
}
// Auto-retry login if session expired (for all other requests)
if (pm.response.code === 401 || pm.response.code === 403) {
console.log("Session expired for: " + pm.info.requestName);
var retryCount = pm.environment.get("authRetryCount") || 0;
if (retryCount < 1) {
console.log("Re-authenticating and retrying...");
pm.environment.set("authRetryCount", retryCount + 1);
pm.environment.set("retryRequest", pm.info.requestName);
// Run login, then come back to this request
pm.execution.setNextRequest("startSession");
} else {
console.log("Authentication retry failed");
pm.environment.set("authRetryCount", 0);
pm.execution.setNextRequest(null);
}
} else {
// Success - only reset retry counter if we were in a retry
if (pm.environment.get("retryRequest") === pm.info.requestName) {
console.log("Retry succeeded, resetting counter");
pm.environment.set("authRetryCount", 0);
pm.environment.set("retryRequest", "");
}
}
Thanks