Hi,
I am able to implement this:
Collection Pre-requisite Script:
utils = {
hello: function() {
return 'hello';
}
}
Request-level Test Script results to hello
in my console:
console.log(utils.hello());
Following this pattern, I have tests which are doing the same thing across my requests thus I’d like to reference them as a global function.
With the following, I am getting ReferenceError: scenario is not defined
when I run my collection.
Collection Pre-requisite Script:
utils = {
verifyStatusCode: function(pm) {
pm.test("Verify status code", function() {
pm.expect(pm.response.code).to.be.equal(scenario.expectedResponseCode);
}
);
}
}
Request-level Test Script is logged as undefined
:
console.log(utils.verifyStatusCode(pm));
I am initializing scenario
in my Request-level Test Script. I am able to log its value as well.
Am I missing something in terms of initializing the local var scenario
which is then used by global function?
Note that I’m avoiding using eval()
as advised here.