question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Run multiple collections sequentially sharing a common environment.

See original GitHub issue

Dear,

I was wondering if it is possible (did not find how) to run sequentially two or more collections, but sharing the same environment.

Something like

newman run authenticate_collection.json api_collection.json -e environment.json

I have a collection that basically login a user and retrieve an access_token. Then I have multiple collection for several APIs. I would not to have to copy/paste each time the authentication folder but share it instead. So the result (access_token) of the authenticate_collection.json would be into the environment, only for the run execution context.

I guess it require to be handle first by postman before newman? Is this something possible? Thanks a lot for your help!

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
ahghatolcommented, May 18, 2021

@shubhamjadon

I tried the solution you have given to run multiple collections.

I observed that with the solution you have provided, the pre-request script does not work. I was trying to set variables (e.g token) in per request script at the collection level.

1reaction
shubhamjadoncommented, Mar 11, 2020

@lusoalex there is no feature like the one you asked currently in postman. But there is a workaround i discovered maybe that could help you. It is as follows:

  1. You can change environment variable using Test Scripts(go through this link for tutorial). The environment variable will get changed after getting a response from collection run.
  2. Then you can use that value in other collection run. As you mentioned it is a access token so you can either add it to url or header of requests.(more info)
  3. Now, above is possible if you can run multiple collections sequentially which is currently not possible in postman. Hence, to run them sequentially you will need to add some lines of code(if you want to do this i suggest that you locally install newman library in a folder and do following changes directly in it) Steps are as follows:
  • Add following code at line 98 (after “var emitter = new EventEmitter(),runner = new runtime.Runner(),stopOnFailure,entrypoint;”) (inside node_modules/newman/lib/run/index.js):
if(_.isArray(options.collection)){
        let obj = {};
        obj.info = options.collection[0].info;
        obj.info.name = "combined";
        obj.item = [];
        for(let i=0; i<options.collection.length; i++){
            obj.item.push({name:"file"+(i+1),item:options.collection[i].item});
        }
        options.collection = obj;
}
  • After adding following changes use newman nodejs module to run your collection. Provide a array of collections like this: (sample app.js)
const newman = require('newman'); // require newman in your project

// call newman.run to pass `options` object and wait for callback
newman.run({
    collection: [require('./authentication_collection.json'),require('./api_collection.json')], 
    reporters: 'cli',
    environment: require('./testEnv.postman_environment.json')
}, function (err) {
	if (err) { throw err; }
    console.log('collection run complete!');
});

(The above only works for newman nodejs module) (Also, if you want info on how to run collection using newman library then see docs)

(The above implementation will combine all the collections into a single collection and then run it. That’s the only way i can think of achieving desired functionality)

I hope this helps.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Newman-Run - GitHub Pages
Run multiple postman collections along with predefined configs using a single feed file. Reduces command-line arguments since reporting (allure, JSON, CLI, ...
Read more >
Required to run multiple collection through Newman - Help
Is there any command to execute multiple collections through single cmd. If you have please share it with me. I'm working on a...
Read more >
Postman - Run Collections using Newman - Tutorialspoint
To run Collections using Newman, we have to first launch the Postman application and click on the three dots available beside the Collection...
Read more >
Batch running multiple Newman (Postman) test collections
You just have to use "call" before newman command as follows: SET postman_collection=Regression.postman_collection.json SET ...
Read more >
CUDA C++ Best Practices Guide
CUDA programming involves running code on two different platforms ... Another common approach to parallelization of sequential codes is to make use of ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found