Usecase:
- Under collection A, multiple folders X,Y,Z are present
- Under folder X -> Execute POST request for multiple iterations of data
- Under folder X -> after completion of POST request for multiple iterations, execute GET request once
- Validate
Solutions tried:
Tried achieving it with Send Next request in Postman as suggested by Sivcan Singh in github
The following is the script tried.
In Folder X-> for POST request - Pre-request script:
currentIterationCount = pm.environment.get('currentIterationCount');
numberOfIterations = pm.environment.get('numberOfIterations');
//set numberOfIterations if not set
if (!numberOfIterations) {
pm.environment.set("numberOfIterations", pm.info.iterationCount);
}
//set currentIteration -> 1 if not set
if(!currentIterationCount) {
pm.environment.set("currentIterationCount",1);
}
else {
pm.environment.set('currentIterationCount', currentIterationCount+1);
}
In Folder X -> for Get Request - Pre-request script:
currentIterationCount = pm.environment.get('currentIterationCount');
numberOfIterations = pm.environment.get('numberOfIterations');
if(currentIterationCount < numberOfIterations)
{
postman.setNextRequest('registerHost');
}
Observations:
- The GET request gets executed even if the Pre-request script is present in the first iteration itself
- The next request when redirected to the POST call, executes the data for first iteration and not the new iteration data.
How should i achieve this case. Postman currently does not support controlling per folder iteration count in a collection.