/**使用者变量信息 */
const randomInt = (min, max) => Math.floor(Math.random() * (max - min + 1)) + min; // 随机整数
const getRandomValue = list => list[randomInt(0, list.length - 1)]; // 随机选项
//随机生成一个字符串作为用户名
postman.setGlobalVariable("compellation", ("0000" +
(Math.random()*Math.pow(36,7) << 0).toString(36)).slice(-7));
//用户昵称,随机2-6字姓名
const charsInName = ['赵', '钱', '孙', '李', '王', '张'];
const numOfChars = randomInt(2, 6);
let randomName = '';
for (let i = 0; i < numOfChars; i++) {
let index = randomInt(0, 5);
randomName += charsInName[index];
}
//environment.nickname = randomName;
postman.setGlobalVariable("nickname",randomName);
/**
//随机生成一个字符串作为昵称
postman.setEnvironmentVariable("nickname", ("0000" +
(Math.random()*Math.pow(36,4) << 0).toString(36)).slice(-4));
*/
//用户性别
const divisions = ['O', 'M', 'F'];
//为什么使用environment无法设置变量? 原因environment是引用环境变量的操作
//environment.sex = getRandomValue(divisions);
postman.setGlobalVariable("sex",getRandomValue(divisions));
//postman.setEnvironmentVariable("sex","O");
//用户身份证号码
//postman.setEnvironmentVariable("card","500106200412055816");
postman.setGlobalVariable("card",`50010620001208${randomInt(1000, 9999)}`);
// 随机生日(时间戳)
// 假设今天是2017-1-1,距1970-1-1 47年,则生日范围为 1923-1-1 ~ 2017-1-1
//environment.birthday = randomInt(0 - Date.now(), Date.now());
//postman.setEnvironmentVariable("birthday",Date.now());
/**
//获取系统当前时间,并组装成固定格式时间戳
var d = new Date();
//将日期组装成2位
var timeDate = d.getDate().toString();
if(timeDate.length == 1){
timeDate = "0" + timeDate;
}
//组装整个时间戳
var timesDate = d.getFullYear() + "-"+(d.getMonth()+1).toString() +"-"+ timeDate;
postman.setEnvironmentVariable("birthday", timesDate);
*/
postman.setGlobalVariable("birthday", '2000-12-08');
//身高
//environment.height = '${randomInt(120, 221)}';
//environment.height = randomInt(120, 221);
postman.setGlobalVariable("height",randomInt(120, 221));
//体重
//environment.weight = '${randomInt(40, 150)}';
//environment.height = randomInt(40, 150);
postman.setGlobalVariable("weight",randomInt(40, 150));
//remark
//随机生成一个字符串作为remark
postman.setGlobalVariable("remark", ("test" +
(Math.random()*Math.pow(36,4) << 0).toString(36)).slice(-4));
// 随机手机
//environment.phone = `18${randomInt(100000000, 999999999)}`;
postman.setGlobalVariable("phone",`18${randomInt(100000000, 999999999)}`);