API Testing - zacisco/notes GitHub Wiki

Postman

Tricks Explaining (How To)

Run request in loop by previous request response (my solve)

  1. CREATE COLLECTION

1st request in collection

Tests section
let res = pm.response.json(); // Array of objects
if (res.length) {
    pm.collectionVariables.set('response', res);
    pm.collectionVariables.set('idx', 0);
}

2nd request in collection

Pre-request Script section
let idx = pm.collectionVariables.get('idx');
let res = pm.collectionVariables.get('response');
if (idx > -1 && idx < res.length) {
    pm.collectionVariables.set('response-some-field', res[idx].some_field);
    pm.collectionVariables.set('idx', ++idx);
    postman.setNextRequest(pm.info.requestId);
}
Tests section
let idx = pm.collectionVariables.get('idx');
let res = pm.collectionVariables.get('response');
if (idx > -1 && idx >= res.length)
    postman.setNextRequest(null);

then Run collection and select needed requests only (our 1st and 2nd in example)


For Browsers

For Devs REST API Test

Chrome

Firefox

⚠️ **GitHub.com Fallback** ⚠️