# Identify if Script is being executed by Collection Runner

**URL:** <https://community.postman.com/t/identify-if-script-is-being-executed-by-collection-runner/11460>\
**Category:** Help Hub\
**Tags:** tests, variables, runner, collection-runner\
**Created:** [March 21, 2020, 10:31am UTC](https://community.postman.com/t/identify-if-script-is-being-executed-by-collection-runner/11460 "2020-03-21T10:31:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![whimsy](https://avatars.discourse-cdn.com/v4/letter/w/3ab097/32.png) [@whimsy](https://community.postman.com/u/whimsy)\
**Post date:** [March 21, 2020, 10:31am UTC](https://community.postman.com/t/identify-if-script-is-being-executed-by-collection-runner/11460/1 "2020-03-21T10:31:47Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![petermacko](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/petermacko/32/26847_2.png) [@petermacko](https://community.postman.com/u/petermacko)\
**Post date:** [February 27, 2024, 2:51pm UTC](https://community.postman.com/t/identify-if-script-is-being-executed-by-collection-runner/11460/2 "2024-02-27T14:51:03Z")

</div>

In my current analysis, I found these two options:

1. 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
2. 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](https://stackoverflow.com/questions/72363743/how-to-know-if-a-request-is-running-from-collection-in-test-script/72363744#72363744))

so to summarize it I recommended solution number 2.

---

<div class="post-metadata">

**Author:** ![Dotnet\_Mob](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/dotnet_mob/32/31520_2.png) [@Dotnet\_Mob](https://community.postman.com/u/Dotnet_Mob)\
**Post date:** [February 4, 2025, 10:36am UTC](https://community.postman.com/t/identify-if-script-is-being-executed-by-collection-runner/11460/3 "2025-02-04T10:36:31Z")

</div>

`if(pm.info.iterationCount>1){}` is helpful when you set iteration count as more than 1.

see the details : [javascript - How to know if a request is running from collection in test script? - Stack Overflow](https://stackoverflow.com/a/79411341/4133590)
