External library in Postman

前端 未结 3 1394
鱼传尺愫
鱼传尺愫 2020-12-31 10:02

I want to use linq.js for my assertions. Is there a way to include an external library in Postman?

3条回答
  •  萌比男神i
    2020-12-31 10:20

    I am doing pretty much the same than @grinderX19.

    I run this once to load my global variable:

    postman.setGlobalVariable("myUtils", function myUtils() {
    let utils = {};
    
    utils.function1= function function1(Arg1, Arg2){
        
    };
    
    utils.function2= function function2(Arg1, Arg2){
        
    };
    
    return utils;
    } + '; myUtils();'
    );
    

    Then, I am calling it like this in Postman requests:

    //import the global variable
    let utils = eval(globals.myUtils);
    
    //Call a function contained by this global variable
    var var1 = utils.function1(arg1, arg2);
    

    Hope this helps.

提交回复
热议问题