If you think Postman is only for static or manual testing, you are not correct. We can do automation testing of API using postman to a good extent. We can add dynamic behavior to Postman requests and collections.
Postman contains a NodeJS based runtime environment. This NodeJS environments allows us to add dynamic behaviour to Postman requests and collections.
- Pre-request Script :- It is executed before a request is sent to server or end points.
2. Test Script :- It is executed once response is received from server.
You can add pre-request and test scripts to a:
- A request within a collection
- A request not saved to a collection.
Execution order of scripts:-
As we know now that Pre-request script will be executed before request is hit to server and tests script will be executed once response is received.
When we create a Collection we can add Pre-request and test scripts in it.
When we create a folder within a Collection, we can add Pre-request and test scripts in it at folder level as well.
When we add a request in a collection or in a folder of collection, we can add Pre-request and test scripts in it at particular request level as well.
As per official document of Postman:-
For every request in a collection, scripts will execute in the following order:
- A pre-request script associated with a collection will run prior to every request in the collection.
- A pre-request script associated with a folder will run prior to every request in the folder.
- A test script associated with a collection will run after every request in the collection.
- A test script associated with a folder will run after after request in the folder.
We will see above execution flow in details with proper examples in upcoming posts.
More about API Testing in upcoming posts. Stay tuned.
If you have any doubt, feel free to comment below.
If you like my posts, please like, comment, share and subscribe.