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?
✗ Incorrect
A condition block runs the code inside it only when the condition is true, helping control test flow.
Which JavaScript keyword is used to start a condition block in Postman tests?
✗ Incorrect
The 'if' keyword starts a condition block to check if a condition is true.
What will happen if the condition in an if block is false in Postman test scripts?
✗ Incorrect
If the condition is false, the code inside the if block does not run.
How can you test for a response status of 200 using a condition block in Postman?
✗ Incorrect
Using if (pm.response.code === 200) lets you run tests only when the status is 200.
What is the purpose of an else block in Postman test scripts?
✗ Incorrect
An else block runs code when the if condition is false, allowing alternative actions.
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.