Bird
Raised Fist0
Postmantesting~20 mins

Generating dynamic data in Postman - Practice Problems & Coding Challenges

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Challenge - 5 Problems
🎖️
Dynamic 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 pre-request script?
Consider this Postman pre-request script that generates a random integer between 1 and 10 and sets it as an environment variable. What will be the value type of the environment variable randomNumber after running this script?
Postman
const randomNumber = Math.floor(Math.random() * 10) + 1;
pm.environment.set('randomNumber', randomNumber);
AA number type, e.g., 7
BA string representing the number, e.g., "7"
CAn object containing the number, e.g., {value: 7}
DUndefined, because environment variables cannot be set dynamically
Attempts:
2 left
💡 Hint
Remember that Postman environment variables store values as strings.
assertion
intermediate
2:00remaining
Which assertion correctly verifies a dynamic timestamp in Postman test script?
You have a response JSON with a field timestamp that contains the current time in ISO format. Which Postman test assertion correctly checks that timestamp is a valid ISO date string?
Postman
const jsonData = pm.response.json();
Apm.expect(Date.parse(jsonData.timestamp)).to.be.NaN;
Bpm.expect(jsonData.timestamp).to.be.a('date');
Cpm.expect(new Date(jsonData.timestamp).toString()).to.not.equal('Invalid Date');
Dpm.expect(jsonData.timestamp).to.equal(new Date().toISOString());
Attempts:
2 left
💡 Hint
Check how JavaScript Date parsing works and how to detect invalid dates.
🔧 Debug
advanced
2:00remaining
Why does this Postman script fail to generate a unique email each time?
This pre-request script is intended to generate a unique email by appending a timestamp, but it always sets the same email value. What is the cause?
Postman
const timestamp = pm.environment.get('timestamp');
if (!timestamp) {
  pm.environment.set('timestamp', Date.now());
}
const email = `user_${timestamp}@example.com`;
pm.environment.set('email', email);
AThe timestamp is set only once and never updated, so email stays the same.
BDate.now() returns a constant value in Postman scripts.
CEnvironment variables cannot be used in pre-request scripts.
DThe email variable is not set correctly due to string interpolation error.
Attempts:
2 left
💡 Hint
Check when and how the timestamp environment variable is updated.
framework
advanced
2:00remaining
Which Postman feature best supports generating dynamic test data for multiple iterations?
You want to run a collection multiple times with different dynamic data generated on each iteration. Which Postman feature allows you to do this most effectively?
AUsing the Collection Runner with a data file containing static values
BManually changing environment variables before each run
CUsing Postman monitors to schedule runs without data variation
DUsing pre-request scripts with dynamic data generation and Collection Runner iterations
Attempts:
2 left
💡 Hint
Think about how to generate fresh data automatically for each iteration.
🧠 Conceptual
expert
2:00remaining
What is the main advantage of using dynamic data generation in API testing with Postman?
Why is generating dynamic data during API tests important instead of using only static test data?
AIt helps simulate real-world scenarios by avoiding data duplication and conflicts.
BIt reduces the need for assertions in test scripts.
CIt guarantees that tests will always pass regardless of API changes.
DIt eliminates the need for environment variables.
Attempts:
2 left
💡 Hint
Think about how static data can cause problems in repeated tests.

Practice

(1/5)
1. What is the main purpose of generating dynamic data in Postman tests?
easy
A. To hardcode fixed values for all requests
B. To slow down the test execution
C. To make tests flexible and simulate real user input
D. To avoid using any variables in tests

Solution

  1. Step 1: Understand dynamic data role

    Dynamic data allows tests to use different values each time, simulating real users.
  2. Step 2: Compare options

    Only To make tests flexible and simulate real user input describes making tests flexible and realistic, which is the main goal.
  3. Final Answer:

    To make tests flexible and simulate real user input -> Option C
  4. Quick Check:

    Dynamic data = flexible, realistic tests [OK]
Hint: Dynamic data means changing values to mimic real users [OK]
Common Mistakes:
  • Thinking dynamic data slows tests
  • Confusing dynamic data with fixed values
  • Ignoring the need for variable data
2. Which of the following is the correct syntax to generate a random integer between 1 and 100 in Postman using dynamic variables?
easy
A. {{random.integer(1,100)}}
B. {{randomInteger(1,100)}}
C. {{randomInt(1,100)}}
D. {{random.int(1,100)}}

Solution

  1. Step 1: Recall Postman random integer syntax

    Postman uses {{random.int(min,max)}} to generate random integers.
  2. Step 2: Check each option

    Only {{random.int(1,100)}} matches the correct syntax exactly.
  3. Final Answer:

    {{random.int(1,100)}} -> Option D
  4. Quick Check:

    Correct syntax = {{random.int(min,max)}} [OK]
Hint: Use {{random.int(min,max)}} for random integers [OK]
Common Mistakes:
  • Using wrong function names like randomInt or randomInteger
  • Using dot instead of function call syntax
  • Missing parentheses or curly braces
3. What will be the output of the following Postman dynamic variable in a request body?
{"userId": "{{random.uuid}}"}
medium
A. {"userId": "a unique UUID string generated at runtime"}
B. {"userId": "random.uuid"} (literal string, no substitution)
C. {"userId": "123e4567-e89b-12d3-a456-426614174000"} (a fixed UUID)
D. {"userId": "{{random.uuid}}"} (variable not replaced)

Solution

  1. Step 1: Understand {{random.uuid}} behavior

    This variable generates a unique UUID string each time the request runs.
  2. Step 2: Analyze output options

    {"userId": "a unique UUID string generated at runtime"} correctly describes a unique UUID generated at runtime, not a fixed or literal string.
  3. Final Answer:

    {"userId": "a unique UUID string generated at runtime"} -> Option A
  4. Quick Check:

    {{random.uuid}} = unique UUID string [OK]
Hint: {{random.uuid}} always creates a new unique ID [OK]
Common Mistakes:
  • Expecting a fixed UUID value
  • Thinking variable is not replaced
  • Confusing with literal string output
4. You wrote {{random.int(10,5)}} in your Postman test to generate a random number between 10 and 5. What is the issue and how to fix it?
medium
A. No issue, it works fine as is
B. The min and max values are reversed; swap them to {{random.int(5,10)}}
C. Use {{random.integer(5,10)}} instead for correct syntax
D. Remove parentheses: {{random.int 5,10}}

Solution

  1. Step 1: Identify parameter order requirement

    Postman expects the first argument as min and second as max; min must be less than max.
  2. Step 2: Fix reversed values

    Swapping 10 and 5 to {{random.int(5,10)}} corrects the range.
  3. Final Answer:

    The min and max values are reversed; swap them to {{random.int(5,10)}} -> Option B
  4. Quick Check:

    Min must be less than max in {{random.int(min,max)}} [OK]
Hint: Min value must be less than max in random.int() [OK]
Common Mistakes:
  • Using reversed min and max values
  • Incorrect function name random.integer
  • Removing parentheses causing syntax errors
5. You want to generate a dynamic email address in Postman that always uses a random username but a fixed domain @example.com. Which of the following is the best way to do this?
hard
A. {{random.username}}@example.com
B. {{random.email}}
C. {{random.username}}@{{random.domain}}
D. {{random.email}}@example.com

Solution

  1. Step 1: Understand requirement

    The username should be random, but domain fixed as '@example.com'.
  2. Step 2: Evaluate options

    {{random.username}}@example.com concatenates a random username with fixed domain correctly. {{random.email}} uses full random email (domain varies). {{random.username}}@{{random.domain}} randomizes domain (not fixed). {{random.email}}@example.com appends fixed domain to full email (invalid).
  3. Final Answer:

    {{random.username}}@example.com -> Option A
  4. Quick Check:

    Random username + fixed domain = {{random.username}}@example.com [OK]
Hint: Combine {{random.username}} with fixed domain for custom emails [OK]
Common Mistakes:
  • Using {{random.email}} which randomizes domain too
  • Randomizing domain when fixed domain is needed
  • Appending domain to full email causing invalid format