0
0
Postmantesting~20 mins

Timestamp generation in Postman - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Timestamp Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this Postman test script timestamp?
Consider this Postman test script snippet that generates a timestamp in milliseconds since Unix epoch. What will be the value of timestamp after running this code?
Postman
const timestamp = Date.now();
console.log(timestamp);
AUndefined, because Date.now() is not a function in Postman scripts
BA string with the current date in ISO format, e.g., '2023-06-17T12:00:00.000Z'
CAn object containing date and time properties
DA number representing milliseconds since January 1, 1970, e.g., 1687000000000
Attempts:
2 left
💡 Hint
Date.now() returns the current time in milliseconds as a number.
assertion
intermediate
2:00remaining
Which assertion correctly verifies a timestamp is recent in Postman?
You want to write a test in Postman to check that a timestamp variable responseTimestamp is within the last 5 seconds. Which assertion is correct?
Postman
const responseTimestamp = pm.response.json().timestamp;
const now = Date.now();
Apm.expect(responseTimestamp).to.be.within(now - 5000, now);
Bpm.expect(responseTimestamp).to.equal(now - 5000);
Cpm.expect(responseTimestamp).to.be.above(now + 5000);
Dpm.expect(responseTimestamp).to.be.a('string');
Attempts:
2 left
💡 Hint
Check if the timestamp is between now minus 5 seconds and now.
🔧 Debug
advanced
2:00remaining
Why does this Postman script fail to generate a valid timestamp?
This Postman test script tries to generate a timestamp but fails. What is the error?
Postman
const timestamp = new Date().getTime;
console.log(timestamp);
Atimestamp is a function reference, not a number, because getTime is missing parentheses
Btimestamp is a string instead of a number
Ctimestamp is undefined because Date() is not called correctly
DSyntaxError due to missing semicolon
Attempts:
2 left
💡 Hint
Check if getTime is called as a function.
🧠 Conceptual
advanced
2:00remaining
What is the difference between Date.now() and new Date().getTime() in Postman scripts?
Both Date.now() and new Date().getTime() return timestamps. What is the key difference?
A<code>Date.now()</code> returns seconds; <code>new Date().getTime()</code> returns milliseconds
B<code>Date.now()</code> returns a string; <code>new Date().getTime()</code> returns a number
C<code>Date.now()</code> is a static method returning milliseconds; <code>new Date().getTime()</code> creates a Date object then returns milliseconds
DThere is no difference; both return the current date as a formatted string
Attempts:
2 left
💡 Hint
One creates an object, the other does not.
framework
expert
3:00remaining
How to reliably test timestamp freshness in Postman for asynchronous APIs?
You have an API that returns a timestamp of when data was last updated. The timestamp is in milliseconds. You want to write a Postman test that passes only if the timestamp is within 10 seconds of the current time, accounting for network delay. Which approach is best?
Postman
const responseTimestamp = pm.response.json().lastUpdated;
const now = Date.now();
AUse <code>pm.expect(responseTimestamp).to.be.a('string');</code> to verify type
BUse <code>pm.expect(responseTimestamp).to.be.within(now - 10000, now + 1000);</code> to allow 1 second future tolerance
CUse <code>pm.expect(responseTimestamp).to.equal(now);</code> for exact match
DUse <code>pm.expect(responseTimestamp).to.be.below(now - 10000);</code> to check if timestamp is older than 10 seconds
Attempts:
2 left
💡 Hint
Allow some tolerance for network delays and clock differences.