如何使用Postman内建变量
小编这次要给大家分享的是如何使用Postman内建变量,文章内容丰富,感兴趣的小伙伴可以来了解一下,希望大家阅读完这篇文章之后能够有所收获。
一、Postman有以下内建变量,适合一次性使用:
{{$guid}}//生成GUID
{{$timestamp}}//当前时间戳
{{$randomInt}}//0-1000的随机整数
二、内建变量的应用举例,获取当前时间戳
// 随机整数const randomInt = (min, max) => Math.floor(Math.random() * (max - min + 1)) + min; pm.globals.set("random_number", randomInt(300,1000)); //从多个选项中选择实现:const randomInt = (min, max) => Math.floor(Math.random() * (max - min + 1)) + min; const getRandomValue = list => list[randomInt(0, list.length - 1)];const charsInName = ['王','李','张'];pm.globals.set("people_name", getRandomValue(charsInName));//随机生成手机号const randomInt = (min, max) => Math.floor(Math.random() * (max - min + 1)) + min; var mobile_num= `18${randomInt(100000000, 999999999)}`;pm.globals.set("mobile_num", mobile_num);//等待const sleep = (milliseconds) => {const start = Date.now();while (Date.now() <= start + milliseconds) {}};sleep(5000) //5秒
看完这篇关于如何使用Postman内建变量的文章,如果觉得文章内容写得不错的话,可以把它分享出去给更多人看到。
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。