Challenge - 5 Problems
Dynamic Assertion Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ assertion
intermediate2:00remaining
Dynamic assertion with timestamp validation
You have a Postman test that checks if the response JSON contains a timestamp field that should be within the last 5 minutes. Which assertion correctly validates this dynamically?
Postman
const responseTime = new Date(pm.response.json().timestamp);
const now = new Date();
const diffMinutes = (now - responseTime) / 60000;Attempts:
2 left
💡 Hint
Think about how to check if the timestamp is within the last 5 minutes, not older.
✗ Incorrect
Option B correctly asserts that the difference in minutes is less than 5, meaning the timestamp is recent. Other options check for wrong conditions.
❓ Predict Output
intermediate2:00remaining
Output of dynamic variable assertion in Postman
Given this Postman test code, what will be the test result if the response JSON is {"count": 10} and the environment variable 'expectedCount' is set to '10' (string)?
Postman
const actualCount = pm.response.json().count; const expectedCount = pm.environment.get('expectedCount'); pm.test('Count matches expected', () => { pm.expect(actualCount).to.eql(Number(expectedCount)); });
Attempts:
2 left
💡 Hint
Check how the expectedCount is converted before assertion.
✗ Incorrect
The code converts expectedCount to a number before comparing, so both sides are numbers 10, making the test pass.
🔧 Debug
advanced2:00remaining
Debugging a failing dynamic assertion in Postman
This Postman test is supposed to check if the response header 'x-rate-limit-remaining' is greater than zero. However, it always fails. What is the cause?
Postman
const remaining = pm.response.headers.get('x-rate-limit-remaining'); pm.test('Rate limit remaining positive', () => { pm.expect(remaining).to.be.above(0); });
Attempts:
2 left
💡 Hint
Check the data type of the header value before comparing.
✗ Incorrect
Headers are strings by default. Comparing string '10' with number 0 using .above fails. Converting to number fixes it.
❓ framework
advanced2:00remaining
Using dynamic variables in Postman pre-request scripts
You want to set a dynamic timestamp variable 'currentTime' in Postman before sending the request, so you can use it in assertions later. Which code correctly sets this environment variable?
Attempts:
2 left
💡 Hint
Remember how to set environment variables and the correct way to get current time as string.
✗ Incorrect
Option A correctly sets the environment variable to the current ISO timestamp string. Option A tries to get instead of set. Option A uses pm.variables which is temporary and stores Date object, not string. Option A sets a function reference, not the timestamp.
🧠 Conceptual
expert2:00remaining
Why use dynamic assertion values in API testing?
Which is the best reason to use dynamic assertion values in Postman tests instead of hardcoded values?
Attempts:
2 left
💡 Hint
Think about test reliability when data changes.
✗ Incorrect
Dynamic assertions allow tests to check values that change, like timestamps or IDs, keeping tests valid and meaningful.