Sree
Sree

Reputation: 31

Executing different postman requests in Pre-request Scripts

I am planning to execute different postman scripts before executing current script.I added following code to call other scripts.

postman.setNextRequest("Get_Name");
postman.setNextRequest("Get_role");

then in current script call login script.

Please let me know whats wrong in this script.

Upvotes: 3

Views: 2175

Answers (1)

n-verbitsky
n-verbitsky

Reputation: 552

The thing is during the collection runner execution postman.setNextRequest() sets next request basing on the name of request in the collection.

Firstly, this script works only during the collection runner.

Secondly, after performing these lines of code the collection runner will skip 'Get_Name' request in your collection and will execute 'Get_role'. If you want Postman to run firstly 'Get_Name' and then 'Get_role' you may try to add postman.setNextRequest('Get_role'); in the Test section of 'Get_Name' request.

On the other hand, you may consider using pm.sendRequest() to send HTTP request directly from the pre-request script tab of your request, so that you don't need to use collection runner.

Upvotes: 1

Related Questions