In Postman, you want to store an authentication token so it is available only during the current session and not saved permanently. Which variable scope should you use?
Think about which variable scope does not persist after the session ends.
Temporary variables set with pm.variables.set() exist only during the request execution and are not saved permanently, making them ideal for session-only tokens.
Given this Postman test script snippet, what will be the console output if the environment variable authToken is not set?
const token = pm.environment.get('authToken'); console.log(token ?? 'No token found');
Consider what the nullish coalescing operator ?? does when the variable is undefined.
If authToken is not set, pm.environment.get() returns undefined. The expression token ?? 'No token found' evaluates to 'No token found'.
Which assertion correctly verifies that a global variable accessToken exists and is a non-empty string in Postman test scripts?
Check which assertion chain correctly tests type and non-empty string.
Option A uses to.be.a('string') to check type and not.empty to ensure the string is not empty, which is the correct way to assert a non-empty string.
Consider this pre-request script snippet that refreshes a token if expired. What is the main reason this script might fail to update the token properly?
const expiry = pm.environment.get('tokenExpiry');
const now = Date.now();
if (now > expiry) {
pm.sendRequest({
url: 'https://api.example.com/refresh',
method: 'POST',
header: { 'Content-Type': 'application/json' },
body: { mode: 'raw', raw: JSON.stringify({ refreshToken: pm.environment.get('refreshToken') }) }
}, (err, res) => {
if (!err && res.code === 200) {
const json = res.json();
pm.environment.set('authToken', json.token);
pm.environment.set('tokenExpiry', Date.now() + json.expiresIn * 1000);
}
});
}Think about how asynchronous calls affect the timing of variable updates in Postman scripts.
pm.sendRequest is asynchronous, so the main request proceeds before the token is refreshed and updated. This means the new token is not used in the current request.
You want to design a Postman collection that securely manages tokens for multiple environments, automatically refreshes tokens when expired, and avoids token leakage in logs. Which approach best meets these requirements?
Consider variable scope, automation of refresh, and security best practices.
Option A uses environment variables scoped per environment, automates refresh in pre-request scripts asynchronously, and disables logging to prevent token exposure, which aligns with best practices.