记一下一些用于Postman的Js脚本
2017-04-01 本文已影响0人
Super7
Pre-request Script
随机获取数组里面的几个值中的一个
var string = "10,20,25,50,75,100";
var array = string.split(","); //字符串转换成数组
var value = array[Math.round(Math.random()*(array.length-1))];
postman.setEnvironmentVariable("size", value);
随机整数
postman.setEnvironmentVariable("pageNumber", parseInt(Math.random()*1));
unix时间戳
postman.setEnvironmentVariable('timestamp',Math.round(new Date().getTime()/1000) );
Tests断言
tests["HttpStatus code is 200"] = responseCode.code === 200;
tests["Response time is less than 300ms"] = responseTime < 300;
var jsonData = JSON.parse(responseBody);
tests["response statusCode"] = jsonData.code === 200;
tests["response message"] = jsonData.status === "SUCCESS";