Alternative way to detect if running from Collection or Send

Hello,

I’ve come across similar discussions as the ones from these two forum posts:

Both topics suggest using the condition postman.__execution.cursor.length > 1 to determine the context of test execution.

However, with the latest version of Postman (11.1.14) that I’m using, it seems ‘postman’ is deprecated. Although it still works for now, it’s likely to be completely removed in the foreseeable future, right?

Additionally, every time this request is executed, a warning message pops up, which is quite bothersome.

I’d like to revisit this topic to find an alternative solution using the new pm.* syntax.

Thanks in advance.

Hey @tuanvu1109 :wave:

Welcome to the Postman community :postman:

The warning you see in the console and the use of that deprecated function are not the same thing.

You’re using postman.setNextRequest() somewhere in your Collection and that should be swapped out to use pm.execution.setNextRequest() - the warning message is telling you that.

@danny-dainton the warning is causing by this code

postman.__execution.cursor.length > 1

Once I remove/comment this line of code, the warning message is totally disappeared.

By the way, my main point in this question is not that warning message, I’m looking for an alternative solution for this postman.__execution.cursor.length > 1 because I do want to detect if the request is running from Collections Runner or just manual click Send button.

I tried

pm.__execution.cursor.length > 1

or

pm.execution.cursor.length > 1

none of them work

I understand the main point of the question.

I’m just trying to get some clarity on your Collection structure, I’m kinda blind here and only you can see what’s in there. :sweat_smile:

Does your collection also contain any setNextRequest() statements which control the flow while run in the runner?

Yes @danny-dainton , I do have setNextRequest() in my collection, but I do use them this way

pm.execution.setNextRequest()

And as I share, if I remove the code above

postman.__execution.cursor.length > 1

all the other script remain same, the warning message will be disappeared :sweat_smile: