How to Write Global Functions in Postman

前端 未结 8 1746
借酒劲吻你
借酒劲吻你 2020-11-30 04:59

I need help writing a common function to use across a collection of requests which will help with building a framework.

I have tried using the below format

8条回答
  •  情歌与酒
    2020-11-30 05:13

    Without eval:

    Define an object containing your function(s) in the collection's pre-request scripts without using let, var, etc. This attaches it to Postman's global sandbox object.

    utils = {
      myFunc: function() {
        return 'hello';
      }
    };
    

    Then within your request's pre-request or test script section just call the function:

    console.log(utils.myFunc());
    

提交回复
热议问题