Dev Raj
Dev Raj

Reputation: 670

Passing multiple iteration-data json files for same collection using newman

Is it possible to pass or iterate 'iteration-data' using multiple data json files ?

Currently we are running our newman tests using below matrix.json from github -

{
    "runs": [
        {
            "name": "Request 1",
            "collection": "api/test/collection/Starview.collection.json",
            "iteration-data": "api/test/collection/starview.data.json",
            "environment": "api/test/collection/environment.json"
        },
        {
            "name": "View-Request 1",
            "collection": "api/test/collection/View.collection.json",
            "iteration-data": "api/test/collection/View1.data.json",
            "environment": "api/test/collection/environment.json"
        },
        {
            "name": "View-Request 2",
            "collection": "api/test/collection/View.collection.json",
            "iteration-data": "api/test/collection/View2.data.json",
            "environment": "api/test/collection/environment.json"
        },
        {
            "name": "View-Request 3",
            "collection": "api/test/collection/View.collection.json",
            "iteration-data": "api/test/collection/View3.data.json",
            "environment": "api/test/collection/environment.json"
        }
    ]
}

In the above example, Request collection and environments are same for all except the first one.

Here is an other way I tried to pass as an array of Iteration-data -

{
        "name": "View-Request 1",
        "collection": "api/test/collection/View.collection.json",
        "iteration-data": ["api/test/collection/View1.data.json","api/test/collection/View2.data.json","api/test/collection/View3.data.json"]
        "environment": "api/test/collection/environment.json"
    },

Which didn't work. It did throw an error as 'Invalid template'.

Error: The template is not valid. .github/workflows/reports-test.yml (Line: 126, Col: 27): A sequence was not expected

I see some example to run from command line as below -

newman run View.collection.json -e environment.json -d View1.data.json -d View2.data.json -d View3.data.json

We run matrix using newman command from github actions like below -

        uses: ./actions/run-newman
        with:
          name: ${{ matrix.runs.name }}
          collection: ${{ matrix.runs.collection }}
          iteration-data: ${{ matrix.runs.iteration-data }},
          environment: ${{ matrix.runs.environment }}

In the above example, I just stated three data files, but it may be 20 or even more. I can't hard code file names / collections. Currently it also takes more time to execute tests using above methods. and main aim is to reduce time that takes.

Is there a way to pass multiple iteration-data files to single collection ?

NOTE: For each data file, we pass both input request and output response, which will be unique for each data file.

Upvotes: 1

Views: 94

Answers (0)

Related Questions