What is the main purpose of using environment variables in Postman?
Think about how you can reuse the same request with different settings.
Environment variables allow you to store values that differ between environments, such as URLs or API keys, so you can switch easily without changing each request.
What will be the output of the following Postman test script if the environment variable userId is set to 12345?
const userId = pm.environment.get('userId'); console.log(`User ID is: ${userId}`); pm.test('Check userId', () => { pm.expect(userId).to.eql('12345'); });
Check how pm.environment.get retrieves the variable and how the assertion compares values.
The environment variable userId is correctly retrieved and equals '12345', so the console logs the value and the test passes.
Which of the following lines correctly sets an environment variable named token to the value abc123 in a Postman pre-request script?
Remember environment variables are set with a specific Postman API method.
The correct method to set an environment variable is pm.environment.set. Other options set different scopes or are invalid.
Which assertion correctly verifies that the environment variable sessionId exists and is not an empty string in a Postman test script?
const sessionId = pm.environment.get('sessionId');Check how to assert a string is not empty and exists.
Option D checks that sessionId is a string and is not empty, which confirms it exists and has a value.
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?
Look at the first line and how it affects the variable on each run.
The script sets count to 1 at the start every time, so incrementing always starts from 1, never accumulating.