0
0
Postmantesting~20 mins

Environment variables in Postman - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Environment Variable Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Purpose of Environment Variables in Postman

What is the main purpose of using environment variables in Postman?

ATo store values that can change between different environments like development, testing, and production
BTo write JavaScript code that runs before sending a request
CTo create collections of API requests for sharing
DTo generate random data for testing
Attempts:
2 left
💡 Hint

Think about how you can reuse the same request with different settings.

Predict Output
intermediate
2:00remaining
Output of Accessing Environment Variable in Test Script

What will be the output of the following Postman test script if the environment variable userId is set to 12345?

Postman
const userId = pm.environment.get('userId');
console.log(`User ID is: ${userId}`);
pm.test('Check userId', () => {
    pm.expect(userId).to.eql('12345');
});
AUser ID is: 12345 (test passes)
BUser ID is: undefined (test fails)
CUser ID is: 12345 (test fails)
DSyntaxError due to incorrect pm.expect usage
Attempts:
2 left
💡 Hint

Check how pm.environment.get retrieves the variable and how the assertion compares values.

locator
advanced
2:00remaining
Correct Locator for Environment Variable in Postman Pre-request Script

Which of the following lines correctly sets an environment variable named token to the value abc123 in a Postman pre-request script?

Apm.globals.set('token', 'abc123');
Bpm.variables.set('token', 'abc123');
Cpm.environment.set('token', 'abc123');
Dpm.request.set('token', 'abc123');
Attempts:
2 left
💡 Hint

Remember environment variables are set with a specific Postman API method.

assertion
advanced
2:00remaining
Assertion to Verify Environment Variable Exists and Is Not Empty

Which assertion correctly verifies that the environment variable sessionId exists and is not an empty string in a Postman test script?

Postman
const sessionId = pm.environment.get('sessionId');
Apm.expect(sessionId).to.equal(null);
Bpm.expect(sessionId).to.exist.and.to.be.empty;
Cpm.expect(sessionId).to.be.undefined;
Dpm.expect(sessionId).to.be.a('string').and.not.empty;
Attempts:
2 left
💡 Hint

Check how to assert a string is not empty and exists.

🔧 Debug
expert
3:00remaining
Debugging Environment Variable Not Updating in Postman

You have this test script in Postman:

pm.environment.set('count', 1);
let count = pm.environment.get('count');
count++;
pm.environment.set('count', count);
console.log('Count is:', count);

After running the request multiple times, the count variable always logs 2. What is the most likely reason?

APostman does not allow updating environment variables in test scripts
BThe environment variable <code>count</code> is being reset to 1 every time before incrementing
CThe <code>count++</code> operation does not change the variable value
DThe console.log statement is incorrect and does not show updated value
Attempts:
2 left
💡 Hint

Look at the first line and how it affects the variable on each run.