Under certain conditions I want to skip current request and continue with other requests.
That other request might be the same request (with other parameters made in the pre-script) or another request.
When the condition fires in the pre-request-script, I do:
pm.execution.skipRequest();
pm.setNextRequest(nextrequestname);
I verified that variable nextRequestname indeed does work; without the skiprequest it will fire (after this request)
I verified that this request was not fired with that skipRequest();
so, it seems that in the pre-request-script the setNextRequest is ignored when skipRequest() is used too.
Is it possible to somehow not execute the request, but still trigger the post-response script? That could be an alternative to setNextRequest in the pre-request.
It not that it’s specifically ignoring .setNextRequest, it’s ignoring all scripts.
Any remaining scripts in the Pre-request tab are skipped, and no tests are run.
As the setNextRequest function would be in the Post-Response script, it’s not going to run.
In order to get what you’re trying to do, the logic would need to be in that previous request in order to move to the next intended request to execute.
You said script stops running after the .SkipRequest. That is not true. Script code after the .SkipRequest does run, but obviously the post-test script does not work (just as I want it to be skipped).
However, I tried the .SetNextRequest from the posttest and that is working.
Trying the .SetNextRequest from the pre-request code will not work, because ‘this’ test cannot be skipped.
I want in the pre-request code select a specific test to run, without running the current test. This is not possible yet, at least not with the combination .SkipRequest and .SetNextRequest.
It depends where you have placed the pm.execution.skipRequest() statement in the pre-request script. If you have some logic, tests, console logs or whatever else before that statement it will run that in the Script because it wouldn’t know that you want to skip the request yet. If it was on the first line of the pre-request it wouldn’t execute anything after it.
For example, that would hit the first console log statement but not the one after the skipRequest statement.
As you can only use pm.setNextRequest() in the post-response script, it wouldn’t run that because the request wouldn’t have been sent so there would be no response and the post-response script wouldn’t be executed.
This wouldn’t execute any of this post-response script
I don’t have any idea what your script looks like so I wouldn’t be able to tell if what you have runs after that skipRequest statement or not.
Just a reminded that the setNextRequest() function will only work in the Collection Runner and has no effect if you’re trying to see that working when sending a single request.
I want in the pre-request code select a specific test to run, without running the current test.
I don’t really understand what you mean here. Are you mixing up Tests with Requests?
It’s probably just me not understanding what you’re trying to do with the current functionality.