Ignoring tests and requests

Is to possible to ignore some requests and tests?
For example, user choose production environment and some tests, requests can’t be completed, And we need to ignore this tests and requests for this environment.

@pieceofquality

  1. Requests can be ignored using the inbuilt postman.setNextRequest('Request Name'); function . For instance, if a collection has requests A, B, and C in order, request B can optionally be skipped by calling postman.setNextRequest('C'); in the test script of A.

  2. Tests can be skipped using pm.test.skip, like so:

(skipTest ? pm.test.skip : pm.test)('should be valid', function () {
    // do something here
});

Here, skipTest is an example variable that will be set to true if the test has to be skipped, and false otherwise.

we should use {{url}} comparing for such methods? if ({{url}} == prodUrl) {postman.setNextRequest(‘Request Name’)} if {{url}} == stageUrl {…}, else …
Or it can be better decision? Can we figure out what environment chosen by another method?

For such cases, you can use the following snippet:

var url = pm.environment.get('url'); // this fetches the value from {{url}}

// now, url can be used in any required condition
1 Like

I have more complicated case. i have 20 requests in my collection and make test for whole collection, one request in this collection is secondary (get definitions from html page) and i don’t want to run test for this request…

@pieceofquality The suggested code snippet can work in your described case as well. If the snippet is placed inside a collection/folder level pre-request script, the same test can be made to work on a conditional basis for all your requests. For cases where your request is secondary, the skip condition based on the url environment variable should evaluate to true, which will lead to your test being skipped.

@kunagpal Is it possible to skip the request using the pre-request script of that test ? This is because the request can called from multiple different sources. For example I would like to skip the request if the data file does not have the right data for that request.

That wasn’t possible the last time I tried. By the time the pre-request block is run your request is already queued up to run