0
0
Postmantesting~5 mins

Condition block in Postman - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a Condition block in Postman tests?
A Condition block is a part of the test script where you check if something is true or false, like checking if a response status is 200. It helps decide what to do next based on the result.
Click to reveal answer
beginner
How do you write a simple condition block to check if the response status is 200 in Postman?
Use an if statement like:
if (pm.response.code === 200) { pm.test('Status is 200', () => { pm.expect(pm.response.code).to.equal(200); }); }
Click to reveal answer
beginner
Why are condition blocks useful in Postman tests?
They let you run tests only when certain things happen, like testing a feature only if the previous request succeeded. This saves time and makes tests smarter.
Click to reveal answer
beginner
What happens if the condition in a Postman condition block is false?
The code inside the block does not run. This means the test inside won’t execute, so you can control which tests run based on conditions.
Click to reveal answer
intermediate
Show an example of using an else block in Postman test scripts.
Example:
if (pm.response.code === 200) { pm.test('Success', () => { pm.expect(true).to.be.true; }); } else { pm.test('Failure', () => { pm.expect.fail('Response was not 200'); }); }
Click to reveal answer
What does a condition block in Postman test scripts do?
ARuns code only if a condition is true
BRuns code regardless of any condition
CDeletes the response data
DSends a new request automatically
Which JavaScript keyword is used to start a condition block in Postman tests?
Aif
Bfor
Cwhile
Dswitch
What will happen if the condition in an if block is false in Postman test scripts?
AThe test always passes
BThe code inside the block runs
CPostman crashes
DThe code inside the block does not run
How can you test for a response status of 200 using a condition block in Postman?
Apm.test('Status is 200')
Bif (pm.response.code === 200) { pm.test(...) }
Cpm.response.code = 200
Dpm.expect(200).to.equal(pm.response.code)
What is the purpose of an else block in Postman test scripts?
ATo stop the test execution
BTo repeat the if block
CTo run code when the if condition is false
DTo send another request
Explain how a condition block works in Postman test scripts and why it is useful.
Think about checking response status before running tests.
You got /4 concepts.
    Write a simple Postman test script using a condition block to check if the response status is 200 and explain each part.
    Start with if, then pm.test inside, then pm.expect to check status.
    You got /5 concepts.