Collection composition
I have done some spikes into composing collections so that a business use-case can be created by composing individual collections. In the process, I have examined the different components that can overlap and thought you guys might appreciate the insight.
Before I go ahead and create my own little library, is this something postman team will be interested in pursuing?
That’s a great. At Postman we support and appreciate our community leveraging the collection concept itself to amplify the value they derive out of Postman platform.
I would love to see what you develop and would be more than glad to be part of the process in any way feasible. At the moment, composing collections to form a scenario is in our feature list but not in near term horizon.
Sure. So...
Requirements
-
Works on top of collections and doesn't require the collection themselves to have any notion of this sequencing. ie, nothing like
postman.setNextRequest() -
Should ideally work for both postman and newman.
-
Allows the full usage of all scopes. ie,
collectionVariables, etc.
Case study
We examine the following requests and apply different solutions to them. We have three collections of the form:
-
Foo.postman_collection.json: Config => Foo -
Bar.postman_collection.json: Config => Bar -
FooBar.postman_collection.json: (Foo, Bar) => FooBar
Solution A
description
This is currently my only working solution. It's a newman only solution that works with the environment scope only. It makes use of export-environment flag in newman's run command.
We can run:
cp envs.postman_environment.json envs-mutable.postman_environment.json
newman run Foo.postman_collection.json \
-e envs-mutable.postman_environment.json \
--export-environment envs-mutable.postman_environment.json &&
newman run Bar.postman_collection.json \
-e envs-mutable.postman_environment.json \
--export-environment envs-mutable.postman_environment.json &&
newman run FooBar.postman_collection.json \
-e envs-mutable.postman_environment.json \
--export-environment envs-mutable.postman_environment.json
/
The envs-mutable.postman_environment does the job of passing the context around. In this case, the context is only the environment scope variables.
Pros & Cons
- It satisfies requirement 1 beautifully.
- It doesn't respect requirement 2. The composition happens at newman level and is tied to the execution.
- Lastly, doesn't respect requirement 3: The solution is limited to the
environmentscope only sincenewmandoesn't allow exporting the full context/"session".
Summary
This is a good solution for CI purposes that uses Newman.
Solution B
description
Taking the idea behind req.1 a step further, we could say this composition process should happen independently of Postman/Newman and that this process should generate a combined collection. If we can achieve such a combined collection, then the requests can have full access to the collectionVarriables scope too for instance since it's just one big collection. Also, if this is just a single collection, Newman/Postman should just handle it as normal.
I looked around and came across postman-combine-collections. This looked like exactly what I wanted. Sadly it doesn't respect order and it only generates a collection with the specified collections present. If it did, I could have something of the form:
postman-combine-collections --name composed \
-f Foo.postman_collection.json \
-f Bar.postman_collection.json \
-f FooBar.postman_collection.json \
-o composed.collection.json \
/
to generate a single collection which can then be run in Postman/Newman.
Ideally, it should also accept a json with a postman-defined schema, containing an ordered list of the address of the collections to be composed. That would be really handy for CI purposes.
Pros & Cons
- It satisfies requirement 1.
- It satisfies requirement 2. The composition happens independently of execution.
- It satisfies requirement 3.
Summary
The only problem is, there currently isn't a library that supports this ordered combination feature. Ideally, this could be something that can be developed externally to newman/postman. In future, it could perhaps be added to them as a special type of import to Postman and as a command in Newman separate from run.
I would love to see what you develop and would be more than glad to be part of the process in any way feasible.
Hi @shamasis did you get the chance to have a look at this? would love to have your feedback.