A package to run multiple postman collections in single run by leveraging newman library. This will help us to merge and view the results of multiple collections in a single place using allure.
If we need to run multiple postman collections or single postman collections with multiple environments, then it becomes we need to have multiple command lines as,
newman run <file1.json>
newman run <file2.json> -e <env1.json>
newman run <file2.json> -e <env2.json>
...
Also, if we need to have multiple reports along with this run, we need to specify those each of these command line run along with the folder in which the reports should be generated as,
newman run <file1.json> --reporters cli,html,allure --reporter-html-export htmlOutput.html --reporter-allure-export <allure-results-out-dir>
newman run <file2.json> -e <env1.json> --reporters cli,html,allure --reporter-html-export htmlOutput.html --reporter-allure-export <allure-results-out-dir>
newman run <file2.json> -e <env2.json> --reporters cli,html,allure --reporter-html-export htmlOutput.html --reporter-allure-export <allure-results-out-dir>
So, as we can see the params that we are passing in the commandline keeps on increasing and its much difficult to consolidate and have a single report for multiple newman run. In Python or in Ruby test runs we have profiles that we can specify during a run which will have most of the static commandline params.
Also to run different collections at the same time, we need to depend on the shell's default multi run with &&
between multiple newman runs. Here, if we are running three newman runs as,
newman run <file1.json> && newman run <file2.json> && newman run <file3.json>
and if the file2.json
takes long time to run than other two, then if we have any failures in <file1.json>
or <file2.json>
that will not be shown in the jenkins jobs or any CI tools such as bitbucket pipeline. This happens because the result of the run which completes at last takes precedence over others.
This package is aimed at resolving the above particular issue along with allure reports integration which can be easily integrated with jenkins. This allows us to run multiple collections defined in a single json file and run all the collections in one shot and have a combined reports at allure.
- Multiple collections run in single shot
- Allure reports along with newman's default CLI, HTML & JSON
- Jenkins Integration
- Docker Execution
- Need to handle tests with iteration data.
- Need to add multi-thread run. (To parallelize the test run Help Needed)
The easiest way to install Newman-Run is using NPM. If you have Node.js installed, it is most likely that you have NPM installed as well.
npm install -g newman-run
This installs Newman-Run globally on your system allowing you to run it from anywhere. If you want to install it locally, Just remove the -g flag.
If you want this to be added to your package.json, run with either --save
or --save-dev
depending on your usage.
To check for the available commandline arguments use newman-run --help
Here we can see our original aim to run multiple collections in single shot.
For a simple run of all the feature files in normal mode, try
newman-run -c <Feed_file_path_which_contains_input_collections>
Here we are going to use the feed file extensively to make our package run multiple collections at a time. Feed file is nothing but a json file where we need to specify the path of collection and environment JSON's.
The feed file is the core structure for this package to function. In the feed file, one has to specify the collections and environment json files path or the url in the array format inside runs
variable like,
{
"runs":[
{
"collection": "./collections/test_scripts.postman_collection.json"
},
{
"collection": "./collections/file_upload_collection.postman_collection.json",
"environment": "./environment/test_environment.json"
}
]
}
If we have only collections that need to be run as part of the test, then have collection
alone. If we have collection and environment files, then we need to specify both collection
and environment
in json format.
When we initiate the tests, the runs
array will be iterated and all the tests will be run using newman
package.
Ideally we should have the postman collection link as the feed file input, this gives us the leverage of modifying the tests via postman without touching the core framework. The ideal feed file will be,
{
"runs":[
{
"collection": "https://www.getpostman.com/collections/57c3cfef239jeijw39d93"
},
{
"collection": "https://www.getpostman.com/collections/57c3cfef239jeijwew282",
"environment": "./environment/test_environment.json"
},
{
"collection": "https://www.getpostman.com/collections/57c3cfef239jeijwew282",
"environment": "./environment/dev_environment.json"
},
{
"collection": "https://www.getpostman.com/collections/57c3cfef239jeijwew282",
"environment": "./environment/prod_environment.json"
}
]
}
Once the feed file is prepared, one can directly trigger the test by,
newman-run -f <Feed_file_which_contains_input_collections>
Now as you can see, you can specify N number of environment combinations with the same collection file or different collection file. All these will run in one shot and we can have a collated result view in the allure.
To support the basic newman
functionality, the newman-run
command allows you to specify a collection to be run. You can easily export your Postman Collection as a json file from the Postman App and run it using Newman.
newman-run -c <./collection/<example_collection.json>
If your collection file is available as an URL (such as from our Cloud API service), Newman-Run can fetch your file and run it as well.
newman-run -c <https://www.getpostman.com/collections/3423refwef-dfdfwfw2322-6878-eb55-7943-sadfasadfd-JsLv>
If you have environment file to be passed, you can conviniently do the same.
newman-run -c <./collection/<example_collection.json> -e <./environment/<example_env.json>
or
newman-run -c <https://www.getpostman.com/collections/3423refwef-dfdfwfw2322-6878-eb58u> -e <./environment/<example_env.json>
You can also specifiy both the feed file as well as collections at the same time.
newman-run -f <./feed/<feed_file.json> -c <https://www.getpostman.com/collections/3423refwef-dfdfwfw2322-6878-eb58u>
or
newman-run -f <./feed/<feed_file.json> -c <https://www.getpostman.com/collections/3423refwef-dfdfwfw2322-6878-eb58u> -e <./environment/<example_env.json>
This allows us to run any collection dynamically along with our set of collections.
The above will take care the reporting part and we don't need to mention about that from the command line. Along with allure reports, newman's default CLI, HTML and JSON reports are added which can be found at reports/
path. For sophesticated classification, reports for each collection is isolated with different name. If needed JSON and HTML files can be pushed to S3 for further processing or to have a record.
In order to remove the report files that are generated in the previous run, run command of -r
can be added. This will clear the reports folder and then will have only the files that are corresponding to the current run.
newman-run -r -f <./feed/<feed_file.json>
or
newman-run -r -f <./feed/<feed_file.json> -c <https://www.getpostman.com/collections/3423refwef-dfdfwfw2322-6878-eb58u> -e <./environment/<example_env.json>
We need to give the file path along with the current working directory i.e., along with ./
symbol. This ensures that the proper file path is given and its used to compute the relative path in the code.
To open the allure results,
allure serve reports/allure
To install allure follow https://docs.qameta.io/allure/ with your respective machine.
Get any of the linux with cypress docker image as the slaves in jenkins and use the same for executing the UI automation with this framework (Sample docker image - https://hub.docker.com/r/postman/newman/
). From the jenkins bash Execute the following to get the testcases to run (Provided newman-run is added to the package.json dependencies),
#!/bin/bash -l
npm list
ls
cd <path_to_the_project>
npm install
newman-run -f <./feed/<feed_file.json>
In Jenkins pipeline, try to add the following snippet to execute the tests,
pipeline {
agent { docker { image 'postman/newman' } }
stages {
stage('build') {
steps {
sh 'cd project/'
sh 'npm install'
sh 'newman-run -f <./feed/<feed_file.json>' # or different files
}
}
}
}
If you are looking for proper framework structure up on which this package is built on you can see Postman-Newman-Framework
- Newman - Automation core framework to run Postman collections.
- Newman-Allure - For Detailed reporting.
- Clone the repo!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Create a pull request.
Please read CONTRIBUTING.md for details on code of conduct, and the process for submitting pull requests.
This project is licensed under the GNU GPL-3.0 License - see the LICENSE file for details
- To all the open source contributors whose code has been referred in this project.