You have a Postman collection with 3 requests. Each request returns a JSON response with a field status. The collection runs sequentially and you use a test script to count how many responses have status equal to success.
After running the collection, what is the value of the counter if the responses are: {"status": "success"}, {"status": "fail"}, {"status": "success"}?
let successCount = Number(pm.environment.get('successCount') || 0); pm.test('Count success status', function () { let jsonData = pm.response.json(); if (jsonData.status === 'success') { successCount++; } pm.environment.set('successCount', successCount); });
Count only responses where status is exactly success.
Only the first and third responses have status equal to success, so the count is 2.
You want to store a variable in Postman that is accessible by all requests during a collection run but does not persist after the run ends. Which variable scope should you use?
Think about variables that exist only during the collection run and are shared by all requests in that collection.
Collection variables exist only during the collection run and are shared by all requests in that collection. Environment and global variables persist beyond the run.
What error does this Postman test script produce?
pm.test('Response has userId', () => {
let jsonData = pm.response.json()
pm.expect(jsonData.userId).to.eql(123);
});Check if the code syntax and function calls are correct.
The code uses arrow function syntax correctly and calls pm.expect properly. Missing semicolons are optional in JavaScript and do not cause errors here.
You have a Postman collection with 100 requests. Running it sequentially takes a long time. Which approach optimizes the total run time?
Think about running multiple requests at the same time.
Postman Runner allows setting concurrency to run multiple requests in parallel, reducing total run time.
In a collection run, you try to increment a variable counter in the test script of each request like this:
let count = pm.variables.get('counter');
count++;
pm.variables.set('counter', count);But after the run, counter remains unchanged. Why?
Check if the variable exists before incrementing.
If 'counter' is not set initially, pm.variables.get('counter') returns undefined. Incrementing undefined results in NaN, so the variable is not updated properly.