Scripts which execute only once per collection run #8120
-
I have started using Insomnia and I really love it. I have been using the pre-request and after-request scripts quite a while now, but what I a missing (or was not able to find yet), is a way to execute a script only once per collection run. My use case here would be that I need a random number (or uuid or similar) or a date which is generated once and then stays the same across the collection run. I thought about putting a pre-request script at the top level and check with "insomnia.environment.has()" if a particular variable is set and if not set it. But I also need to clean it afterwards and I failed to find a nice way to do it. Any help would be greatly appreciated. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Beta Was this translation helpful? Give feedback.
-
Thanks for the answer. I solved it in a similar fashion. I am just using the first request in each block and add a pre-request script. The solution with the "skipRequest" is a nice one, though. |
Beta Was this translation helpful? Give feedback.
This is an interesting topic 👍 . Hm currently there is no capability for setup or teardown.
One way I can think of is adding 2 requests for them, and calling
insomnia.execution.skipRequest()
to skip sending request from pre-req script, here is an example (setup is similar):And set them as the first and the last one.
It is still not optimal although it doesn't send out the request.