简体   繁体   English

测试以计算环境中有多少变量(邮递员)

[英]Test to count how many variables are in a environment (Postman)

I'd like to count how many environment variables I have in an Environment in POSTMAN.我想计算 POSTMAN 的环境中有多少环境变量。

In my Environment called, UUID Test , I have 10 variables that I have set:在名为UUID Test的环境中,我设置了 10 个变量:

UUID_1
UUID_2
UUID_3
..
UUID_10

I've tried a number of versions which I put into the Test field in the Request (see below)我已经尝试了多个版本,我将它们放入请求中的测试字段(见下文)

V1: V1:

let counter = parseInt(pm.environment.get("counter"))
console.log(counter)

V2: Using the Environment name in quotes. V2:在引号中使用环境名称。

let counter = parseInt(pm.environment.get("UUID Test"))
console.log(counter)

With both of these versions I am receiving a Nan in the console.对于这两个版本,我在控制台中都收到了Nan What am I missing here?我在这里想念什么?

Try尝试

console.log(Object.keys(pm.environment.toObject()).length)

That should give you that length of the variables in the environment file.这应该为您提供环境文件中变量的长度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM