I am running mock server in Postman which basically sends responses on specific requests. Both response and requests contain Environmental variables of String type which should be unique and I change them before each request to my mock server which is quite annoying.
I would like to have these variables updated by pre-request script before I receive response. I have seen similar question here, but it doesn't work for me — I have tried putting script below to Tests tab to the Request I am mocking response for, but it is not executed.
function makeid(length) {
var result = '';
var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
var charactersLength = characters.length;
for ( var i = 0; i < length; i++ ) {
result += characters.charAt(Math.floor(Math.random() *
charactersLength));
}
return result;
}
pm.environment.set("unique_id", makeid(7));
pm.environment.set("payment_id", makeid(10));
Please tell if Postman is able at all to execute scripts before sending responses from its Mock server or it is not possible? If it is not able to do so, then are there any ways to automatically update variables before each request?