Flip boolean value

Hi there. How should I write this
a = !a
in the ‘Tests’ tab?

Every second request the value of ‘a’ should be changed, but I’m not sure how to properly write it.

Hi @janeyack, Welcome to the community!

For such a use case, you may need to use postman variables (global, collection, or environment). For simplicity, below is the test code using global variables for the above use case.

let a = pm.globals.get("a");
if (a === true) {
    pm.globals.set("a", false);
}else {
    pm.globals.set("a", true);

Hope this helps :slight_smile:


Are you iterating over the same request or are you going through multiple requests in a collection? That makes a difference in how this code should be written and where it is written :slight_smile: