Scenario suites in Postman, run by Newman
API suites written as scenarios: one ordered chain of requests per business flow, run in Postman and in CI with Newman.
A design note: the shape, when it is the right one, and what it costs.
Scroll sideways to see the whole diagram.
What a scenario’s scripts do
Nothing hardcoded
Every value is generated at send time, including any signature the API expects.
Shared helpers
Kept in a collection variable, because Postman scripts cannot import files.
Data-driven runs
A CSV or JSON file turns one scenario into a table of cases.
Flow control
setNextRequest() for loops and branches — a jump that only works in the runner.
What those scripts look like
Sketches in Postman’s script API, written for this page to show the shape. They are not taken from a project.
// Pre-request script: nothing in the request is typed in by hand.
const body = {
invoiceNo: `INV-${Date.now()}`,
// From the data file when the run has one: one row per case.
amount: Number(pm.iterationData.get('amount')) || _.random(100, 5000),
}
pm.variables.set('body', JSON.stringify(body)) // the raw body is {{body}}
// The signature the API expects, over the bytes that are sent.
const signature = CryptoJS.HmacSHA256(
pm.variables.get('body'),
pm.environment.get('signingSecret'),
).toString(CryptoJS.enc.Base64)
pm.request.headers.upsert({ key: 'X-Signature', value: signature })
// Collection pre-request script: the helpers, kept as text.
pm.collectionVariables.set('helpers', `({
expectStatus: (code) => pm.response.to.have.status(code),
save: (name, path) =>
pm.collectionVariables.set(name, _.get(pm.response.json(), path)),
})`)
// Any request's tests: read them back and use them.
const h = eval(pm.collectionVariables.get('helpers'))
h.expectStatus(200)
h.save('paymentToken', 'data.paymentToken') // for the next request
// Tests of "Inquire payment": ask again until it settles.
const status = pm.response.json().status
const tries = Number(pm.collectionVariables.get('tries') || 0) + 1
pm.collectionVariables.set('tries', tries)
if (status === 'PENDING' && tries < 5) {
pm.execution.setNextRequest('Inquire payment') // this request again
} else {
pm.collectionVariables.unset('tries')
pm.test('the payment settles', () => pm.expect(status).to.eql('SUCCESS'))
}
When it is right, and what it costs
- The cost
- One broken request stops every request after it.
- Why retries do not help
- The failure is a broken precondition, not a flaky call. Retrying a request whose input is already wrong returns the same wrong answer.
- When it is still right
- When the flow is what is under test. Then the order is the point, not a cost.
- The alternative
- Tests that set up their own data and run side by side, as the suites on the front page do. The sequential shape still suits the flow tests.