In a Collection, the requests are executed in the sequence in which they are created. However, a workflow can be changed in Postman. To illustrate it, let us take a Collection having four requests.
To trigger that Collection, click on the arrow appearing to the right of the name of the Collection in the sidebar. The Run button appears, click on it.
The Collection Runner window gets launched. Within the RUN ORDERsection, the sequence in which the requests shall get executed is displayed from the top to bottom. In our example, the order is −
Click on Run Collection1.
A new window appears containing the execution details. With the workflow as −
GET – Executed first.
POST – Executed second.
DEL – Executed third.
PUT – Executed last.
Let us try to execute the requests in the order given below −
GET – To be executed first.
POST – To be executed second.
PUT – To be executed third.
DEL – To be executed last.
This change in workflow can be achieved using the function postman.setNextRequest(). It is used to point to the next request to be run. The name of the next request to be executed is passed as a parameter.
postman.setNextRequest("next request name")
The steps to change a workflow are listed below −
Step1 − Incorporate the below script for the Create User request under the Tests tab,
Step2 − Incorporate the below script for the Update Request under the Tests tab,
Step3 − Incorporate the below script for the Delete Request under the Tests tab,
Step4 − Trigger the collection – Collection1 for execution.
Step5 − A new window opens showing the new sequence of request execution as given below:
GET – executed first.
POST – executed second.
PUT – executed third.
DEL – executed last.