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?
const userIds = [101, 102, 103]; for (let i = 0; i < userIds.length; i++) { pm.environment.set('lastUserId', userIds[i]); }
Think about what happens to the variable lastUserId inside the loop on each iteration.
The loop sets lastUserId to each user ID in the array in order. After the loop finishes, the variable holds the last value assigned, which is 103.
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?
const users = pm.response.json().users;
Check which method ensures every user is active.
every() returns true only if all elements satisfy the condition. Option B uses this correctly. Option B checks if some are active, which is not enough. Option B checks if any inactive user exists but is less direct. Option B counts active users but is more complex.
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?
const items = ['a', 'b', 'c']; for (var i = 0; i < items.length; i++) { pm.environment.set('item', items[i]); }
Consider how environment variables are stored and named.
Each call to pm.environment.set with the same key overwrites the previous value. To store all items, unique keys per iteration are needed.
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?
Think about how Postman supports data-driven testing.
The Collection Runner supports looping through data files to run requests multiple times with different inputs. This is the standard way to loop through test data in Postman.
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?
Consider how to run multiple async calls efficiently and wait for all to finish.
Using Promise.all allows running multiple pm.sendRequest calls in parallel and waiting for all to complete before proceeding. Option A runs sequentially, which is slower. Option A does not wait and may cause race conditions. Option A is incorrect as Postman supports async calls.