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
If you want to call pm.sendRequest in a global function, try this:
Define the global function in collection pre-request, like this:
pm.globals.set('globalFunction', parameters => {
console.log(parameters);
pm.sendRequest('https://google.com/', function(err, resp) {
pm.expect(err).to.not.be.ok;
});
});
Use function like this:
eval(globals.globalFunction)('hello world!!');
Note that, I declared function using arrow style ()=>{}. Otherwise, it wouldn't work.