0
0
Postmantesting~20 mins

Random data generation in Postman - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Random Data Master
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 script generating a random integer?
Consider this Postman pre-request script snippet that generates a random integer between 1 and 10 inclusive. What is the possible output stored in the variable randomInt?
Postman
const randomInt = Math.floor(Math.random() * 10) + 1;
pm.environment.set('randomInt', randomInt);
console.log(randomInt);
AAny integer from 1 to 10 inclusive
BAny integer from 0 to 9 inclusive
CAny integer from 1 to 9 inclusive
DAny integer from 0 to 10 inclusive
Attempts:
2 left
💡 Hint
Remember how Math.random() and Math.floor() work together to generate integers in a range.
assertion
intermediate
2:00remaining
Which assertion correctly verifies a random email format in Postman test script?
You want to check that a randomly generated email stored in pm.environment.get('randomEmail') matches the pattern username@domain.com. Which assertion is correct?
Postman
const email = pm.environment.get('randomEmail');
Apm.test('Email format is valid', () => { pm.expect(email).to.have.string(/^[\w.-]+@[\w.-]+\.com$/); });
Bpm.test('Email format is valid', () => { pm.expect(email).to.equal(/^[\w.-]+@[\w.-]+\.com$/); });
Cpm.test('Email format is valid', () => { pm.expect(email).to.include(/^[\w.-]+@[\w.-]+\.com$/); });
Dpm.test('Email format is valid', () => { pm.expect(email).to.match(/^[\w.-]+@[\w.-]+\.com$/); });
Attempts:
2 left
💡 Hint
Check which assertion method tests a string against a regular expression.
🔧 Debug
advanced
2:00remaining
Why does this Postman script fail to generate a random UUID correctly?
This script tries to generate a random UUID and set it as an environment variable. Why does it fail?
Postman
const uuid = '{{$guid}}';
pm.environment.set('randomUUID', uuid);
console.log(uuid);
Apm.environment.set() cannot store strings generated dynamically.
BThe variable {{$guid}} is not recognized in pre-request scripts and returns the string literally.
Cpm.variables.replaceIn() is asynchronous and needs await keyword.
DThe console.log() statement causes the script to fail.
Attempts:
2 left
💡 Hint
Check how Postman handles dynamic variables in scripts.
🧠 Conceptual
advanced
2:00remaining
What is the main advantage of using Postman dynamic variables for random data generation?
Why should testers prefer Postman dynamic variables like {{$randomInt}} or {{$randomEmail}} over hardcoded test data?
AThey automatically validate the data format without assertions.
BThey guarantee the same data every time for consistent test results.
CThey help create unique test data each run, reducing false positives from duplicate data.
DThey run faster than hardcoded data because they are cached.
Attempts:
2 left
💡 Hint
Think about test data uniqueness and test reliability.
framework
expert
3:00remaining
Which Postman test script snippet correctly generates and validates a random date within the last 30 days?
You want to generate a random date within the last 30 days and verify it is not in the future. Which snippet does this correctly?
A
const now = new Date();
const past = new Date(now.getTime() - 30*24*60*60*1000);
const randomTime = past.getTime() + Math.random() * (now.getTime() - past.getTime());
const randomDate = new Date(randomTime);
pm.environment.set('randomDate', randomDate.toISOString());
pm.test('Date is not in future', () => { pm.expect(randomDate.getTime()).to.be.at.most(now.getTime()); });
B
const now = new Date();
const past = new Date(now.getTime() - 30*24*60*60*1000);
const randomTime = past.getTime() + Math.random() * (past.getTime() - now.getTime());
const randomDate = new Date(randomTime);
pm.environment.set('randomDate', randomDate.toISOString());
pm.test('Date is not in future', () => { pm.expect(randomDate.getTime()).to.be.at.most(now.getTime()); });
C
const now = new Date();
const past = new Date(now.getTime() - 30*24*60*60*1000);
const randomTime = past.getTime() - Math.random() * (now.getTime() - past.getTime());
const randomDate = new Date(randomTime);
pm.environment.set('randomDate', randomDate.toISOString());
pm.test('Date is not in future', () => { pm.expect(randomDate.getTime()).to.be.at.most(now.getTime()); });
D
const now = new Date();
const past = new Date(now.getTime() - 30*24*60*60*1000);
const randomTime = now.getTime() + Math.random() * (now.getTime() - past.getTime());
const randomDate = new Date(randomTime);
pm.environment.set('randomDate', randomDate.toISOString());
pm.test('Date is not in future', () => { pm.expect(randomDate.getTime()).to.be.at.most(now.getTime()); });
Attempts:
2 left
💡 Hint
Check how the randomTime is calculated between past and now timestamps.