postman

Postman: Is it possible to stop a postman call from being executed based on conditions detected in pre-requisite scripts?


I am using the pre-request script in the first call to dynamically generate essential environment variables for the entire script. I also want the users to be notified of those failures when running via collection runner without having to look up to the console. Is it possible to generate information in tests or some other alternative so failures are explicit in the collection runner results?

e.g. if the ip has not been provided in the environment, it does not make sense to run the login call. So i would like to write in a pre-requisite script:

if (!environment['IP']) {
    //do not execute any further and do not send the REST call
}

I tried using:

if (!environment["xyz"]) {
    tests["condtion1"]=false
}

but it gives the error:

There was an error in evaluating pre-requisite script: tests is not defined

Is there any workaround - I don't want to move this code to the tests tab as I don't want to clutter the code there with unrelated environment conditioning.


Solution

  • A throw works just fine. (Updated with excellent tip from @Joe White)

    if (!environment['X']) {
        throw new Error('No "X" set')
    }
    

    This prevents the REST call from going through. But in the collection runner mode it stops the entire test suite.

    But when coupled with newman collection runner it works just fine.