I set enviroment variable and want to check SID data for local and develop machines. After sending request I get the same result - is checked only else statemant.
Please, help me understand why if statement is ignored in any case.
Thanks so much.
if (condition) {
// block of code to be executed if the condition is true
} else {
// block of code to be executed if the condition is false
}
To add additional conditions you would need to use else if
if (condition1) {
// block of code to be executed if condition1 is true
} else if (condition2) {
// block of code to be executed if the condition1 is false and condition2 is true
} else {
// block of code to be executed if the condition1 is false and condition2 is false
}
You could make use of pm.environment.name here to check the active environment name, rather that a value within it:
if(pm.environment.name === 'local') {
// do something...
} else if (pm.environment.name === 'develop') {
// do something...
} else {
// do not do anything...
}
Kindly help me out in this oneโฆ similarly one issue my โฆ else if part is NOT workingโฆ correctly
let jsonData = pm.response.json();
let contextAction = ["New", "Confirm", "Different" ]
//console.log(jsonData.contextAction);
if(jsonData.contextAction === "New") {
console.log(jsonData.contextAction);
pm.test(`Verify the ContextAction Value is -> ${jsonData.contextAction}`,()=>{
pm.expect(jsonData.contextAction).to.be.eqls("New");
})
} else if (jsonData.contextAction === "Confirm") {
pm.test(`Verify the contextAction Value is -> ${jsonData.contextAction}`,()=> {
pm.expect(jsonData.contextAction).to.be.eqls("Confirm");
//pm.expect(jsonData.contextAction).to.be.oneOf(contextAction)
})
} else {
pm.test(`Verify the contextAction Value is -> ${jsonData.contextAction}`,()=>{
pm.expect(jsonData.contextAction).to.be.eqls("Different");
})
}
Hi @ppoorna ,
first of all you can check and see that console.log(jsonData.contextAction);
the result is undefined. It means you can not check in your if block undefined condition.
You should set an variable and then get it in condition. Using variables
Please check it and look above on my issue and solution.
@harutharut well, i understand it, but the issue is not on the variables i did some research that postman is not supporting the โif else if elseโ ladder
Pretty sure its just because you have a few }) in the wrong places.
If you post code, can you please use the preformatted text option in the editor, so it aligns correctly and is easier to read. (Also easier to see mistakes in code).
let contextAction = "Confirm";
if (contextAction === "New") {
console.log("New");
} else if (contextAction === "Confirm") {
console.log("Confirm")
} else {
console.log("Different")
}