Skip to content

Commit

Permalink
doc : update readme with procedure
Browse files Browse the repository at this point in the history
  • Loading branch information
ebalpe committed Nov 19, 2019
1 parent c852fed commit 97f3c1f
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 17 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
node_modules
postman/integ.postman_environment.json
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Running multiple Postman Collection in parallel

A known limitation of the Postman Collection Runner is that it can only execute collection in a consecutive way.
This is just a simple implementation of the solution explained in this [StackOverflow conversation](https://stackoverflow.com/a/41181892/2042761).

## Create your Postman Collection and corresponding tests

Here I needed to attack first `/api/persons` to get the list of persons ids.

![Test of /api/persons](docs/api-persons-test.png)

And then `/api/persons/:id` for each person in the list.

![Test of /api/persons/:id](docs/api-persons-id-test.png)

To do that I used the `postman.setNextRequest()` tricks that specify the next request that will be executed in the collection run. And in each run I get the last personId and pop() it from the array in environment variables.

## Export your collection and the environment variables

![Export collection](docs/export-collection.png)

And save the files in a `postman/` directory.

## Create the new npm project

Simply run `npm init -y` and install the 3 dependencies: `npm i async newman path`

## The script !

It's kind of self explanatory, update the path for your postman collection and environment, specify the number of concurrent run you want to launch with the constant `PARALLEL_RUN_COUNT` and execute the script with `npm start`

![running results](docs/run-result.png)
Binary file added docs/api-persons-id-test.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/api-persons-test.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/export-collection.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/run-result.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 11 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
var path = require('path'),
async = require('async'), //https://www.npmjs.com/package/async
newman = require('newman'),
const path = require('path')
const async = require('async')
const newman = require('newman')

parametersForTestRun = {
collection: path.join(__dirname, 'postman_collection.json'), // your collection
environment: path.join(__dirname, 'integ.postman_environment.json'), //your env
reporters: 'cli'
};
const PARALLEL_RUN_COUNT = 2

const parametersForTestRun = {
collection: path.join(__dirname, 'postman/postman_collection.json'), // your collection
environment: path.join(__dirname, 'postman/localhost.postman_environment.json'), //your env
reporters: 'cli'
};

parallelCollectionRun = function (done) {
newman.run(parametersForTestRun, done);
};

let commands = []
for (let index = 0; index < 5; index++) {
for (let index = 0; index < PARALLEL_RUN_COUNT; index++) {
commands.push(parallelCollectionRun);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@
"value": "http://localhost:8082",
"enabled": true
},
{
"key": "flexiti",
"value": "http://localhost:8081",
"enabled": true
},
{
"key": "token_tad",
"value": "eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJObnBHVmFPRXBXMTI1RllVbzNNRUdyN0ZRdllINFZab1JoTFlFcDA1bzNRIn0.eyJqdGkiOiJlYTBkMWVlNC0yNjE5LTQzNWMtYWI5Yi1iOWMyM2Y2MDk5MmYiLCJleHAiOjE1NzQxODY2NzksIm5iZiI6MCwiaWF0IjoxNTc0MTUwNjgyLCJpc3MiOiJodHRwOi8vbG9jYWxob3N0OjMyNzcyL2F1dGgvcmVhbG1zL1ZBTF9ERV9HQVJPTk5FIiwiYXVkIjpbInJlYWxtLW1hbmFnZW1lbnQiLCJhY2NvdW50Il0sInN1YiI6Ijc2MWYzMjk0LWFiZDYtNGI1Mi04Yjg3LWMyOWI1Y2Q0YzY1ZSIsInR5cCI6IkJlYXJlciIsImF6cCI6Im9raW5hLXNlcnZpY2VzLXB1YmxpYyIsIm5vbmNlIjoiODExN2M0MDYtMWUwNy00YmI5LWFiMTgtYmFlNmJ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wmAfYZQ7ziLwz5gG0P53egI5brA-L3srvvCfux6_JG8aHwRnkdnd-8pR0Eor8d9CVO60QL1xZAD_ie37ZkLbbMbcY-w",
Expand Down
3 changes: 1 addition & 2 deletions postman_collection.json → postman/postman_collection.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"info": {
"_postman_id": "797c42bb-24a5-4b7f-af65-6b81b319696d",
"name": "TAD OKINA",
"name": "DEMO",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
Expand Down

0 comments on commit 97f3c1f

Please sign in to comment.