0
0
Postmantesting~20 mins

Why variables avoid hardcoding in Postman - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Variable Mastery in Postman
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Why use variables instead of hardcoding values in Postman?

In Postman, why is it better to use variables instead of hardcoding values like URLs or tokens directly in requests?

AVariables allow easy updates in one place without changing every request manually.
BHardcoding values makes requests run faster and more securely.
CVariables increase the file size of the Postman collection unnecessarily.
DHardcoding values prevents accidental changes during testing.
Attempts:
2 left
💡 Hint

Think about how many requests might use the same URL or token.

🧠 Conceptual
intermediate
2:00remaining
What is a key benefit of avoiding hardcoded tokens in Postman?

Why should you avoid hardcoding authentication tokens directly in Postman requests?

ATokens stored as variables can be refreshed or changed without editing each request.
BHardcoded tokens reduce the chance of token expiration errors.
CHardcoded tokens improve security by hiding them in the request body.
DTokens must be hardcoded to work with Postman environments.
Attempts:
2 left
💡 Hint

Consider what happens when a token expires or changes.

Predict Output
advanced
2:00remaining
What is the output of this Postman test script?

Given this Postman test script, what will be the console output after running?

Postman
pm.environment.set('userId', '12345');
const userId = pm.environment.get('userId');
console.log(`User ID is: ${userId}`);
pm.test('Check userId variable', () => {
    pm.expect(userId).to.eql('12345');
});
AUser ID is: null (test fails)
BUser ID is: 12345 (test passes)
CSyntaxError due to missing semicolon
DUser ID is: undefined (test fails)
Attempts:
2 left
💡 Hint

Check how the variable is set and retrieved from environment.

assertion
advanced
2:00remaining
Which assertion correctly checks a variable is not hardcoded in Postman?

You want to assert that the 'apiUrl' variable is used instead of a hardcoded URL in your request. Which assertion is correct?

Apm.expect(pm.request.url).to.eql('https://hardcoded.url');
Bpm.expect(pm.environment.get('apiUrl')).to.eql('https://hardcoded.url');
Cpm.expect(pm.environment.get('apiUrl')).to.not.eql('https://hardcoded.url');
Dpm.expect(pm.request.url).to.not.eql(pm.environment.get('apiUrl'));
Attempts:
2 left
💡 Hint

Think about how to confirm the variable differs from a hardcoded string.

🔧 Debug
expert
3:00remaining
Why does this Postman test fail to update the variable?

Review this Postman test script. Why does the variable 'sessionToken' not update as expected?

Postman
pm.variables.set('sessionToken', 'abc123');
const token = pm.variables.get('sessionToken');
pm.test('Token is set', () => {
    pm.expect(token).to.eql('abc123');
});
pm.variables.set('sessionToken', 'xyz789');
const newToken = pm.variables.get('sessionToken');
pm.test('Token updated', () => {
    pm.expect(newToken).to.eql('xyz789');
});
AThe test script syntax is invalid due to missing semicolons.
BThe variable name 'sessionToken' is reserved and cannot be updated.
Cpm.variables.set requires a callback function to update variables asynchronously.
Dpm.variables only sets variables for the current request scope, not environment, so update is lost after request.
Attempts:
2 left
💡 Hint

Consider the difference between pm.variables and pm.environment variables.