Chain and reuse Postman and Newman requests to cover all API usage scenarios
npm install toastmanjavascript
const newman = require("newman");
const toastman = require("toastman");
const pathToCollection = "./myCollection.json";
const pathToChains = "./myChains.json";
//this will return new collection accroding chains file
//you can pass paths {string} or objects {object} as an arugments
let outCollection = toastman(pathToCollection, pathToChains);
//or you can do it like that
const collection = require(path.resolve(pathToCollection));
const chains = require(path.resolve(pathToChains));
//if you need, of course
outCollection = toastman(collection, chains);
`
Also you can enable verbose mode from code using setVerbose method
`javascript
toastman.setVerbose(true||false);
`
$3
>Type toastman --help to get more information
`bash
toastman
-p path-to-postman-collection
-t path-to-toastman-chains
-o path-to-output-file
`
This will generate a new Postman collection file according to chaining rules written inside toastman chain file. The structure of this file is simple.
`json
{
"chains": [
{
"name": "chain1",
"requests": ["req1", "req1", "req2"]
},
{
"name": "chain2",
"requests": ["folder1/req1InsideFolder1", "folder2/request1InsideFolder2"]
}
]
}
`
Name of the chain might be used to name your sequence test scenario.
Param|Type|Description
---|:---:|---
name | string | Name of the chain
requests| string[] | Array of the requests name. Those names should be equal to the ones that in the loaded collection. If the request are inside folder, then you can combine it through "/". Example: Folder name: "foo" Request name: "bar"
You can write as "foo/bar" into array. Take a look into example.
Writing tests inside Postman
There are no restrictions on code inside original Postman collection. You still can use prerequest and test scripts for each request. Toastman adds additional global variable called toastman-chain` that indicating which chain is currently running. You could use this variable to perform more precies testing depend from the context in which current request has been executed.