Newman: Can we skip a particular network request from execution, in a collection? postman.setNextRequest is to swich to some request. Byt here I need to skip particular request from execution.

Created on 25 Nov 2016  ยท  15Comments  ยท  Source: postmanlabs/newman

  1. Newman Version (can be found via newman -v):
  2. OS details (type, version, and architecture):
  3. Are you using Newman as a library, or via the CLI?
  4. Did you encounter this recently, or has this bug always been there:
  5. Expected behaviour:
  6. Command / script used to run Newman:
  7. Sample collection, and auxilliary files (minus the sensitive details):
  8. Screenshots (if applicable):

feature request

Most helpful comment

How to skip the execution of request A ?

All 15 comments

Hey @Freakishmahesh, postman.setNextRequest can help achieve request skipping as well. Consider the following workflow:

  1. A collection has three requests, A, B, and C.
  2. You decide to skip request B, say. (Or any intermediate lying request, for that matter).
  3. The test script of request A would include a postman.setNextRequest("C");.
  4. Thus, request B would never be run.

This will not work if you wish to skip the first / last request in a collection, however.

@Freakishmahesh How did this go for you? :thinking:

@kunagpal Thank you for words. As you said, cannot skip first/last in a collection. Even if setNextRequest("C"), I cannot see anywhere in the reports that Request B has skipped :(

That's odd. How exactly did you use postman.setNextRequest? Please check out the following example collection in Newman, and the Postman collection runner:

{
    "variables": [],
    "info": {
        "name": "skipped-requests",
        "_postman_id": "3ae56cc9-f7dd-f70d-f1c0-45d19fbf32e3",
        "description": "",
        "schema": "https://schema.getpostman.com/json/collection/v2.0.0/collection.json"
    },
    "item": [
        {
            "name": "A",
            "event": [
                {
                    "listen": "test",
                    "script": {
                        "type": "text/javascript",
                        "exec": [
                            "tests[\"Status code is 200\"] = responseCode.code === 200;",
                            "postman.setNextRequest(\"C\");"
                        ]
                    }
                }
            ],
            "request": {
                "url": "https://echo.getpostman.com/get?val=a",
                "method": "GET",
                "header": [],
                "body": {
                    "mode": "formdata",
                    "formdata": []
                },
                "description": "This request always runs first"
            },
            "response": []
        },
        {
            "name": "B",
            "event": [
                {
                    "listen": "test",
                    "script": {
                        "type": "text/javascript",
                        "exec": [
                            "tests[\"Status code is 200\"] = responseCode.code === 200;"
                        ]
                    }
                }
            ],
            "request": {
                "url": "https://echo.getpostman.com/get?val=b",
                "method": "GET",
                "header": [],
                "body": {
                    "mode": "formdata",
                    "formdata": []
                },
                "description": "This request is always skipped in the collection runner / Newman"
            },
            "response": []
        },
        {
            "name": "C",
            "event": [
                {
                    "listen": "test",
                    "script": {
                        "type": "text/javascript",
                        "exec": [
                            "tests[\"Status code is 200\"] = responseCode.code === 200;"
                        ]
                    }
                }
            ],
            "request": {
                "url": "https://echo.getpostman.com/get?val=c",
                "method": "GET",
                "header": [],
                "body": {
                    "mode": "formdata",
                    "formdata": []
                },
                "description": "This request always runs last"
            },
            "response": []
        }
    ]
}

I didn't see information about skipped requests details in the command prompt summary . What do I expect is to have, requests count and names of skipped requests.
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ โ”‚ executed โ”‚ failed โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ iterations โ”‚ 1 โ”‚ 0 โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ requests โ”‚ 6 โ”‚ 0 โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ test-scripts โ”‚ 6 โ”‚ 0 โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ prerequest-scripts โ”‚ 0 โ”‚ 0 โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ assertions โ”‚ 5 โ”‚ 0 โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ total run duration: 15s โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ total data received: 3.45KB (approx) โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ average response time: 2.3s โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

@Freakishmahesh Well, this would be a good addition to Newman, thanks for bringing this up! :+1:

+1

I don't want to run request C.
How can i do that ?
Req : A, B and C
@kunagpal

@jayanthktn In the test script of request B, you can add the following statement:

postman.setNextRequest(null);

Thanks @kunagpal

This will be taken up as part of execution control support in scripts

How to skip the execution of request A ?

I need to skip request A and B for de 2nd iteration. How can I do it? Please help

Is there a way to skip Req A and Req B for the 2nd iteration and only execute Req C ?

This will be taken up as part of execution control support in scripts

Is there an issue reference that can be shared here to track for support for this feature?

Was this page helpful?
0 / 5 - 0 ratings