3
votes

The need here is to run a pre-request script before each call in a folder of a postman collection, optionally, while running from Newman collection.

For example, if running a test suite of 10 calls in one folder, the call would usually be:

newman run <collectionPath> --folder <folderPath>

Is there any option of passing something like,

newman run <collectionPath> --folder <folderPath> --pre-request_script someScript.js --test_script someTest.js

?

The reason why (an obvious) postman collection test / pre-request script is not being used is that

  1. (the main reason) huge amounts of collections are already written and it will be difficult to go into each one of them and add this code. It will be way more convenient to govern this behavior via command line.

  2. the test / pre-request script may vary across different newman runs and these parameters would remove the need of complex conditional code within pre-requests / test scripts.

Is there any other alternative or solution for the same?

1

1 Answers

3
votes

From the latest version you can add pre-requests, tests, variables directly to the collection or something different on each sub folder. These collections can just be used in the normal way via newman. It might solve your problem.

http://blog.getpostman.com/2017/12/13/keep-it-dry-with-collection-and-folder-elements/