@npm_identt/newman-helpers
v1.0.5
Published
A custom Newman helpers
Downloads
8
Maintainers
Readme
identt-newman-helpers
assertJsonTemplate
Getting Started
This package is used to compare two jsons in postman.
How to use
Add pre-request script to your postman collection:
window = {};
pm.sendRequest(`https://unpkg.com/@npm_identt/[email protected]/assertJsonTemplate.js`, (err, res) => {
var text = res.text();
window.assertJsonTemplate = eval(text);
});
Remember! pm.sendRequest()
must contain the latest version of the image.
Positive case
For example pm.response.json()
:
{
"key0": "0",
"key1": "1",
"key2": "2",
"key3": "3"
}
Test case for the request to compare two jsons:
const data = {
"key0": "0",
"key2": "2"
}
pm.test("Example test", () => {
window.assertJsonTemplate(pm.response.json(), data);
})
The test results will look like this:
PASS Example test
Negative case
For example pm.response.json()
:
{
"key0": "0",
"key1": "1",
"key2": "2",
"key3": "3"
}
Test case for the request to compare two jsons:
const data = {
"key0": "0",
"key2": "6"
}
pm.test("Example test", () => {
window.assertJsonTemplate(pm.response.json(), data);
})
The test results will look like this:
FAIL Example test | AssertionError: expected '2' to deeply equal '6'
retryOnFailure
Getting Started
This package is used to retry request when fails.
How to use
Add pre-request script to your postman collection:
window = {};
pm.sendRequest(`https://unpkg.com/@npm_identt/[email protected]/retryOnFailure.js`, (err, res) => {
var text = res.text();
window.retryTest = eval(text);
window.retryOptions = {failed: false}
});
Remember! pm.sendRequest()
must contain the latest version of the image.
Example
retryTest = (testName, postman, setTimeout, specFunction, options={}) => {
...
where testName
is message about test result, postman
and setTimeout
are required arguments to corectly working this function, specFunction
is a place for assertions and options
is a dict where you can set optional parameters as sleepBetweenTries
(sleep time between requests in ms, default is 5000) and numberOfRetries
(number of retries, default is 4).
window.retryTest("Status code is 200", postman, setTimeout, () => {
pm.response.to.have.status(200);
});
window.retryTest("Response time is within acceptance criteria", postman, setTimeout, () => {
pm.expect(pm.response.responseTime).to.be.below(10*1000);
});
To enable retry option, you need to set RUN_COLLECTION_WITH_RETRY
environment to true
. If you skip this environment, retry option will work as pm.test("", () => {});
.