When you run a Postman collection, what is the main reason it helps validate the API flows?
Think about what happens when you run multiple requests in order and check their results.
Running a collection sends each request in order and verifies responses. This confirms that the API behaves correctly through the entire flow, not just individual calls.
Consider this Postman test script inside a request in a collection:
pm.test('Status code is 200', () => {
pm.response.to.have.status(200);
});
pm.test('Response has userId', () => {
const jsonData = pm.response.json();
pm.expect(jsonData).to.have.property('userId');
});If the API response is {"userId": 5, "name": "Alice"} with status 200, what will be the test result?
Check the status code and presence of 'userId' in the response.
The response status is 200, so the first test passes. The response JSON has 'userId', so the second test also passes. Both tests succeed.
You want to add a test in Postman to check that the API response time is less than 500 milliseconds. Which assertion is correct?
Look for the property that holds response time and the correct comparison method.
pm.response.responseTime holds the response time in milliseconds. Using to.be.below(500) correctly asserts it is less than 500ms.
Look at this test script inside a Postman request:
pm.test('Check user name', () => {
const data = pm.response.json();
pm.expect(data.name).to.eql('John');
});The API response is {"name": null}. What is the reason the test fails?
Compare the expected value with the actual response value.
The test expects 'name' to be 'John', but the response has 'name' as null, so the assertion fails.
When running a Postman collection that tests a user registration and login flow, why is it important to use environment variables to store data like userId or authToken?
Think about how data from one request can be used in the next during a flow.
Environment variables let you save values from one request (like userId) and reuse them in later requests, enabling the collection to validate the entire flow dynamically.