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.