In Postman, why is it better to use variables instead of hardcoding values like URLs or tokens directly in requests?
Think about how many requests might use the same URL or token.
Using variables means if a value changes, you update it once in the variable, and all requests using it update automatically. Hardcoding requires changing each request manually, which is slow and error-prone.
Why should you avoid hardcoding authentication tokens directly in Postman requests?
Consider what happens when a token expires or changes.
Tokens often expire or need updating. Storing them as variables lets you update once, and all requests use the new token automatically. Hardcoding requires editing each request, which is inefficient and error-prone.
Given this Postman test script, what will be the console output after running?
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'); });
Check how the variable is set and retrieved from environment.
The script sets 'userId' in environment variables, then retrieves it correctly. The console logs the value, and the test checks it equals '12345', so it passes.
You want to assert that the 'apiUrl' variable is used instead of a hardcoded URL in your request. Which assertion is correct?
Think about how to confirm the variable differs from a hardcoded string.
Option C asserts the environment variable 'apiUrl' is not equal to the hardcoded URL, confirming the variable is used instead of hardcoding. Other options either check equality or compare request URL incorrectly.
Review this Postman test script. Why does the variable 'sessionToken' not update as expected?
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'); });
Consider the difference between pm.variables and pm.environment variables.
pm.variables sets variables only for the current request execution and does not persist changes to environment or global variables. To update variables across requests, pm.environment.set or pm.globals.set should be used.