Problem: I want to set a counter variable (a numeric value) in environment variable, so in "Test" we can control the flow.
My experiment: I wrote a simple API call with following-
Prescript sets the counter variable-
postman.setEnvironmentVariable("mycounter", 1);
Test verifies the counter variable, if its value equals to 1, increment it by one-
if (postman.getEnvironmentVariable("mycounter") == 1 ) {
    postman.setEnvironmentVariable("result", "YES");       
    postman.setEnvironmentVariable("mycounter", 
        1+postman.getEnvironmentVariable("mycounter")); 
} 
else {
    postman.setEnvironmentVariable("result", "NO"); 
}
But when i check the value for "mycounter"-
Can anybody point out 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"); 
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With