Run request inside another single request as pre-request

Issue: Can’t find a way to run request inside another request without running the whole collection.

I want to be able to call a request from the same collection as a pre-request script inside another request without running the whole collection. This will allow me to run tests independently and as a collection. Test should be runnable through Newman and directly from Postman.

All examples that I was able to find so far are related to running whole collection and chaining tests inside it instead of executing single request that runs another request as part of the pre-request script. Writing request in JS in pre-request script is also not the best idea because this will produce a lot of duplicates.

The only way to control the flow is to use setNextRequest() and that only works with the test runners.

Building request workflows | Postman Learning Center

If you want to execute another request as a pre-request step to setup the conditions for the current request, then this can be done using sendRequest() but it is additional code.

How about separating your tests into folders. The folders will run in order, and this will allow you to run all folders, or just a single one which may have multiple steps (this may also have some duplication).

The way I see this, and this is purely from a testing lens.

The Collection is the Test Suite
The folder is the Test Case.
The individual requests are the Test Steps.

I get the point about reusing test steps, because if you have 10 Test Cases which utilise a login feature and that feature changes, you have to update all 10 Test Cases (perhaps a feature request for future Postman development). It’s an important feature in automation which is why you have the concepts of page object model, etc.

On a side note, I try and put any setup for a particular request\test in the pre-request scripts as I’m not generally testing the setup per se. You can add tests to the setup and bail if you don’t get the responses you want, like an authentication token for a login, but this again uses setNextRequest which requires the runner. For example, if I’m logging into an Azure Web App. I use the pre-request script to get the authentication directly from the microsoft login API, as technically I’m not really interested in testing that aspect which is controlled by Microsoft. I am interested in the page I land on after this step, and that it shows the elements linked to that user role. (Microsoft will also eventually block you if you try and automate the login using the GUI\http requests). You can also put these as individual requests one after the other.

I like using the pre-request scripts as it fits into the Given, When, Then BDD style in Agile testing.

Given a known state (pre-request script).
When I do something (the actual request).
Then (your actual tests, the tests tab).