Does anyone know if there is a way - inside a Script (Pre-request Script or Tests) - to identify if the request is being executed in the context of the Collection Runner?
The use case being, Iād like to prevent (accidental) invoking requests that are put in a folder made for Collection Runs only.
I realize I could introduce additional environments for this but it would require duplicating several environments for the purpose, and I just want a simple check to prevent someone triggering the requests outside the Collection Runner.
In my current analysis, I found these two options:
use variable pm.environment.id if this id contains word collection it was executed by Collection runner or using the standard send button as a single request. But when it is executed using CLI this word is not present in the ID parameter
use variable postman.__execution.cursor.length. There is a length of the executed batch (in runner, CLI, and also send button). In case when there is number 1 it is possible that the request was executed using the Send button as single request. But when there is a higher number request was sent using runner or CLI. There is also the possibility that there will be number 1 in case of CLI or Runner but in the case you are running a single request in them. (source: javascript - How to know if a request is running from collection in test script? - Stack Overflow)
so to summarize it I recommended solution number 2.