0
0
Postmantesting~20 mins

Looping in flows in Postman - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Postman Looping Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this Postman test script loop?

Consider this Postman test script that loops through an array of user IDs and sets environment variables. What will be the value of the environment variable lastUserId after the script runs?

Postman
const userIds = [101, 102, 103];
for (let i = 0; i < userIds.length; i++) {
    pm.environment.set('lastUserId', userIds[i]);
}
AlastUserId = 102
BlastUserId = 101
ClastUserId = undefined
DlastUserId = 103
Attempts:
2 left
💡 Hint

Think about what happens to the variable lastUserId inside the loop on each iteration.

assertion
intermediate
2:00remaining
Which assertion correctly verifies all items in a Postman response array?

You receive a JSON response with an array of user objects. You want to assert that every user has an active property set to true. Which Postman test assertion is correct?

Postman
const users = pm.response.json().users;
Apm.test('All users active', () => { pm.expect(users.some(u => u.active === true)).to.be.true; });
Bpm.test('All users active', () => { pm.expect(users.every(u => u.active === true)).to.be.true; });
Cpm.test('All users active', () => { pm.expect(users.find(u => u.active === false)).to.be.undefined; });
Dpm.test('All users active', () => { pm.expect(users.filter(u => u.active === true).length).to.equal(users.length); });
Attempts:
2 left
💡 Hint

Check which method ensures every user is active.

🔧 Debug
advanced
2:00remaining
Why does this Postman loop not set all variables as expected?

This Postman script tries to set environment variables for each item in an array but only the last variable is set. What is the main reason?

Postman
const items = ['a', 'b', 'c'];
for (var i = 0; i < items.length; i++) {
    pm.environment.set('item', items[i]);
}
AThe variable name 'item' is the same in each iteration, so it overwrites previous values.
BThe loop uses 'var' instead of 'let', causing a scope error.
Cpm.environment.set cannot be called inside loops.
DThe array 'items' is empty, so the loop never runs.
Attempts:
2 left
💡 Hint

Consider how environment variables are stored and named.

framework
advanced
2:00remaining
How to loop through a collection of requests in Postman using the Collection Runner?

You want to run a set of requests multiple times with different data sets in Postman. Which approach correctly uses looping in the Collection Runner?

AWrite a for loop inside the Pre-request Script to call pm.sendRequest multiple times for each data set.
BManually duplicate requests in the collection for each data set and run them sequentially.
CUse a data file (CSV/JSON) with multiple rows and run the collection with the Collection Runner to loop through each data row.
DUse the Postman Console to execute the same request repeatedly by clicking run multiple times.
Attempts:
2 left
💡 Hint

Think about how Postman supports data-driven testing.

🧠 Conceptual
expert
3:00remaining
What is the best way to handle asynchronous loops in Postman test scripts?

You need to perform multiple asynchronous API calls in a loop inside a Postman test script and wait for all to complete before continuing. Which approach correctly handles this?

AUse <code>Promise.all</code> with an array of <code>pm.sendRequest</code> promises to run all requests in parallel and await completion.
BUse a regular <code>for</code> loop with <code>pm.sendRequest</code> calls without awaiting, relying on Postman to handle concurrency.
CPostman test scripts do not support asynchronous calls; all requests must be synchronous.
DUse <code>async/await</code> inside a <code>for...of</code> loop to await each <code>pm.sendRequest</code> call sequentially.
Attempts:
2 left
💡 Hint

Consider how to run multiple async calls efficiently and wait for all to finish.