els*_*sar 13
不,linq.js或者Postman Sandbox中没有的任何库都不能在Postman中使用(默认情况下,有一种解决方法).
实际上,如果您在请求中获取脚本,eval则可以在Postman中使用它.本博客文章中给出了一个例子 - http://blog.getpostman.com/2015/09/29/writing-a-behaviour-driven-api-testing-environment-within-postman/
我所做的与@grinderX19 几乎相同。
我运行一次以加载我的全局变量:
postman.setGlobalVariable("myUtils", function myUtils() {
let utils = {};
utils.function1= function function1(Arg1, Arg2){
<code>
};
utils.function2= function function2(Arg1, Arg2){
<code>
};
return utils;
} + '; myUtils();'
);
Run Code Online (Sandbox Code Playgroud)
然后,我在 Postman 请求中这样称呼它:
//import the global variable
let utils = eval(globals.myUtils);
//Call a function contained by this global variable
var var1 = utils.function1(arg1, arg2);
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助。