Postman实现变量自增循环执行接口

roselearn / 2023-05-04 / 原文

设置globals全局变量,如下图设置的n,配置初始值为1或者为其它值

 在接口中添加变量

 在Pre-request Script中设置自增的脚本

var temp = parseInt(postman.getGlobalVariable("n"));  #先获取全局变量n并赋值为temp
temp += 1; #temp自增1
postman.setGlobalVariable("n", temp); #再将自增后temp的值赋给n 

结果如下,从2开始依次获取n的值