我想使用linq.js作为我的断言。有没有办法在Postman中包含一个外部库?
答案 0 :(得分:13)
不,eval
或Postman Sandbox中没有的任何库都无法在Postman中使用(默认情况下,有一种解决方法)。
实际上,如果您在请求中获取脚本并{{1}},则可以在Postman中使用它。此博客文章中提供了一个示例 - http://blog.getpostman.com/2015/09/29/writing-a-behaviour-driven-api-testing-environment-within-postman/
答案 1 :(得分:3)
我做的和@ 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();'
);
然后,我在邮递员要求中这样称呼它:
//import the global variable
let utils = eval(globals.myUtils);
//Call a function contained by this global variable
var var1 = utils.function1(arg1, arg2);
希望这会有所帮助。
答案 2 :(得分:1)
自2015年以来,Postman的bugtracker中有一个开放功能:Loading External JS Files #1180,但似乎他们没有积极地进行这项工作。
与此同时,我正在使用one of the comments中提到的解决方法,即将最小化的自定义JS放在全局变量中,然后将其加载到每个使用此代码的脚本的开头:
eval(postman.getGlobalVariable("environment variable key"));