1. Obtain the environment variable content
var ostype = pm.environment.get("ostype");
2. Set the global variable content
postman.setEnvironmentVariable("ts",Math.floor(new Date().getTime()/1000));
3.auth signature
var auth = CryptoJS.SHA1(pm.environment.get("device_secret"),{asString: true}); postman.setEnvironmentVariable("auth", auth);
4. random identifier
const randomInt = (min, max) => Math.floor (Math.random () * (max - min + 1)) + min; // random integer const getRandomValue = List => List [randomInt (0, List.length --1)]; // random option const chars = [ ' A ' , ' B ' , ' C ' , ' D ' , ' E ' , ' F ' , ' G ' , ' H ' , ' I ' , ' G ', 'k', 'l', 'm', 'n', 'o', '1']; let identifier = ''; for (let i = 0; i < 5; i++) { identifier += getRandomValue(chars); } pm.environment.set("identifier", identifier);
5.schema check
JSON the let; the try { JSON = the JSON.parse (the responseBody); } the catch (ERR) { Tests [ ' server did not return valid JSON format. Please check the service, or reverse proxy network setting (skip the rest of the assertion) ' ] = to false; Tests [ `[the INFO] returns: the responseBody} {$`] = to true; console.error (ERR); } IF (JSON) { const Result = tv4.validateResult (JSON, Schema); the console.log (Result); Tests [ ' the JSON format correct the Schema ' + result.error] = result.valid; } the else { console.error (result.error); console.error (the responseBody); }