Postman创建类

tzdcorbm  于 5个月前  发布在  Postman
关注(0)|答案(2)|浏览(86)

我的目标很简单,我想创建一个名为Helper的类来存储我的集合的所有公共数据/方法。
这就是我计划的方式:x1c 0d1x
在主预请求脚本中,这是代码:

var HELPER = pm.globals.get("HELPER");

console.log(HELPER.mandatory);
console.log(HELPER.checkIfEmpty());

字符串
我可以检索强制变量,但不能调用checkIfEmpty
我得到以下消息:TypeError: HELPER.checkIfEmpty is not a function
正如你所看到的,这个方法是存在的。
我检查了这个link,但没有成功。
你知道我错过了什么吗?

hujrc8aj

hujrc8aj1#

我找到了一种方法来管理我所期望的:


的数据
和主预请求脚本代码:

console.log(helper.mandatorySubIssues());
console.log(helper.checkIfEmpty("Hello World"));

字符串

ecfdbz9o

ecfdbz9o2#

这基本上就是我现在正在做的。如果你想支持这个特性请求,请添加到这个feature request

相关问题