postman 获取接口参数_Postman接口测试系列:接口参数化和参数的传递

/**使用者变量信息   */

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)}`);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值