How to set numeric value in environment variable
I got workaround. By using Number function convert string to integer.
So
if (postman.getEnvironmentVariable("mycounter") == 1 ) {
postman.setEnvironmentVariable("result", "YES");
postman.setEnvironmentVariable("mycounter", 1+Number(postman.getEnvironmentVariable("mycounter")));
} else {
postman.setEnvironmentVariable("result", "NO");
}
I think the sam's answer works but here is a cleaner way I use in one of my pre-request scripts
let myCounter = +environment["mycounter"]; // '+' Convert String into Integer
if (myCounter == 1) {
myCounter++;
postman.setEnvironmentVariable("result", "YES");
postman.setEnvironmentVariable("mycounter", myCounter);
} else {
postman.setEnvironmentVariable("result", "NO");
}
More informations about converting ==> https://stackoverflow.com/a/1133814/1646479