0
0
Postmantesting~20 mins

Dynamic assertion values in Postman - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Dynamic Assertion Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
assertion
intermediate
2: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;
Apm.test('Timestamp is recent', () => { pm.expect(diffMinutes).to.be.at.least(5); });
Bpm.test('Timestamp is recent', () => { pm.expect(diffMinutes).to.be.below(5); });
Cpm.test('Timestamp is recent', () => { pm.expect(diffMinutes).to.equal(5); });
Dpm.test('Timestamp is recent', () => { pm.expect(diffMinutes).to.be.above(5); });
Attempts:
2 left
💡 Hint
Think about how to check if the timestamp is within the last 5 minutes, not older.
Predict Output
intermediate
2: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));
});
ATest passes because pm.expect does type coercion automatically
BTest fails because actualCount is number but expectedCount is string
CTest fails with TypeError due to type mismatch
DTest passes because actualCount (10) equals Number(expectedCount) (10)
Attempts:
2 left
💡 Hint
Check how the expectedCount is converted before assertion.
🔧 Debug
advanced
2: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);
});
Apm.expect cannot compare header values
BHeader name is incorrect; should be 'X-Rate-Limit-Remaining' with capitals
Cremaining is a string, so the numeric comparison fails; convert to number first
Dpm.response.headers.get returns an array, not a string
Attempts:
2 left
💡 Hint
Check the data type of the header value before comparing.
framework
advanced
2: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?
Apm.environment.set('currentTime', new Date().toISOString());
Bpm.environment.get('currentTime', new Date().toISOString());
Cpm.variables.set('currentTime', new Date());
Dpm.environment.set('currentTime', Date.now);
Attempts:
2 left
💡 Hint
Remember how to set environment variables and the correct way to get current time as string.
🧠 Conceptual
expert
2: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?
ATo ensure tests adapt to changing data and remain valid over time
BTo make tests run faster by avoiding fixed values
CTo reduce the number of tests needed by using random values
DTo avoid writing any assertions manually
Attempts:
2 left
💡 Hint
Think about test reliability when data changes.