Postman脚本处理各种数据的变量

一、变量是字符串里列表, 如 "["100","101","102","103","108"]"

//把字符串的变量处理成列表

var myList=JSON.parse(pm.environment.get('giftTabId')) #giftTabId变量名

//设置随机取值

var randomItem = myList[Math.floor(Math.random() * myList.length)]

//把取得随机值赋值到新得变量名中

pm.environment.set("giftTabId_one",randomItem)

二、变量是列表,如["100","101","102","103","108"]

var array=pm.environment.get('evaluationId')

//设置随机取值

var randomItem = array[Math.floor(Math.random() * array.length)]

//把取得随机值赋值到新得变量名中

pm.environment.set("pingjia_id",randomItem)

相关推荐
程序员小远7 小时前
使用Postman进行一次完整的接口测试
自动化测试·软件测试·python·测试工具·测试用例·接口测试·postman
nangonghen1 天前
centos 7.9安装postman v9.31.0
centos·api·postman
xuegao08072 天前
postman测试webservice服务接口
测试工具·postman
悟能不能悟2 天前
postman怎么获取上一个接口执行完后的参数
前端·javascript·postman
悟能不能悟2 天前
postman中的Tests,怎么获取返回的response中的stateCde
测试工具·postman
晚霞的不甘6 天前
Flutter for OpenHarmony 创意实战:打造一款炫酷的“太空舱”倒计时应用
开发语言·前端·flutter·正则表达式·前端框架·postman
C++ 老炮儿的技术栈8 天前
不调用C++/C的字符串库函数,编写函数strcpy
c语言·开发语言·c++·windows·git·postman·visual studio
木叶子---8 天前
Postman测试WebService接口
测试工具·postman
公链开发9 天前
2026年,可信数据空间 × 区块链:构建国家数据基础设施的核心技术底座与实体落地趋势
区块链·postman