I have some setup javascript that I am running in each folders Pre-request script. This allows me to run a collection or just a single request and get the same output since the initialization is done every time.
However, this initialization process is not the fastest. For this reason I am looking for a way to only run the setup once when I am coming from a collection. But run it every time a single request is run manually.
I have tried to create a dummy request and set a variable. This way when the collection runs it will call this request, which sets the var ‘isCollection’, which will then stop further initializations from running in the other tests with a if statement. The problem is that the next time I run a single test the variable will still be true so the initialization wont run. I could add a request at the end that sets “isCollection” back to false but then if a user stops execution mid run of the collection then the variable wont be set back to false.
I feel like “detect if the run is coming from a folder or collection vs a single test” should be a out of the box feature but I can’t seem to find any way to accomplish this.
This doesn’t address your question, but may address your use case => I have seen separate folders used for Setup, Tests, and Teardown. So when you run the collection, setup and teardown happen as you configured the steps. And when you run a single request, you can still manually execute set up or tests.
@jetison we had something like this originally. I think this works well. My big reason for moving to prerequest scripts is that we didn’t like that a user had to rerun the setup folder every time they wanted to run a request. As in, I run request, get a error that it didn’t work properly, go back and run the setup folder, go back to run my test. Understand that that structure does resolve this though!
I think this is actually what I want “postman.__execution.cursor.position” if the cursor position is 0 I am on the first request the runner is executing.