Open sanjarcode opened 8 months ago
https://www.softwaretestinghelp.com/postman-request-scripts/
pre example (via 'Pre-req.'):
const copiedDocumentDotCookie = ''; const copiedCookiesAsObject = {}; function setGlobals(obj) { Object.entries(obj).forEach(([k, v]) => { pm.globals.set(k, v); }) // pm.globals.set("variable_key", "variable_value"); } pm.test("Content-Type is present", function () { // console.log(pm.response); });
post example (via 'Tests' tab):
const KEYS = ['access-token', 'account', 'token-type', 'client', 'expiry', 'uid']; pm.test("set globals from headers", function setGlobalsFromHeaders() { pm.response.headers.members.forEach(({ key:k, value: v }) => { if(KEYS.includes(k)) { // console.log('Set header', {k, v}) pm.globals.set(k, v); } }) });
https://www.softwaretestinghelp.com/postman-request-scripts/
pre example (via 'Pre-req.'):
post example (via 'Tests' tab):