In Postman, when you send a request, scripts can run in different phases. Which of the following lists the correct order of script execution?
Think about what needs to happen before the request is sent and what happens after.
Postman runs the Pre-request Script first to prepare or modify the request. Then it sends the request. After receiving the response, it runs the Tests Script to check the response.
Consider these Postman scripts attached to a request:
pm.test('Test 1', () => { console.log('Test script running'); });
pm.environment.set('var1', 'value1');And the Pre-request Script:
console.log('Pre-request running');What will be the order of console log outputs when the request is sent?
Remember when each script runs relative to the request.
The Pre-request Script runs first and logs 'Pre-request running'. After the request is sent and response received, the Tests Script runs and logs 'Test script running'.
You want to check if the response status code is 200. Where should you place the assertion?
Assertions check the response after it arrives.
Assertions must be in the Tests Script because it runs after the response is received, allowing you to check response details like status code.
You have a Pre-request Script and a Tests Script both logging messages. You notice the Tests Script logs appear before the Pre-request Script logs in the console. What is the most likely cause?
Think about how console logs accumulate in Postman.
Postman console keeps logs from all requests until cleared. Seeing Tests Script logs before Pre-request logs usually means you are viewing old logs from a previous run.
You run a collection with multiple requests in Postman Collection Runner. You want to run a script once before all requests and once after all requests. Where should you place these scripts?
Think about script scopes in Postman collections.
Collection-level Pre-request Script runs once before all requests in the collection, and Collection-level Tests Script runs once after all requests complete. This is the correct way to run scripts once before all and once after all requests.