Given the following Postman test script, what will be the value of responseVar after execution?
pm.variables.set("userId", 123);
const responseVar = pm.variables.get("userId");pm.variables.set("userId", 123); const responseVar = pm.variables.get("userId");
Remember that pm.variables.set stores a variable and pm.variables.get retrieves its value.
The variable userId is set to the number 123, so retrieving it returns 123.
In a Postman test script, you want to assert that the variable {{token}} is not an empty string. Which assertion is correct?
Think about how to check that a string is not empty using Postman assertions.
Option A correctly asserts that the variable is not empty. Options A, C, and D check for empty, undefined, or null, which are not what we want.
In Postman, you want to access the environment variable sessionId inside a test script. Which syntax is correct?
Remember that environment variables are accessed differently than local or global variables.
Option A uses pm.environment.get which is the correct way to get environment variables. Option A is a template syntax not usable directly in scripts, Option A gets local variables, and D accesses global variables.
Consider this Postman request URL: https://api.example.com/users/{{user}}. The variable user is set in the collection variables. The test script contains:
pm.variables.set('user', 'alice');Why does the URL not replace {{user}} with 'alice' when the request runs?
Think about when variable substitution happens in Postman and which variable scopes affect it.
pm.variables.set sets a local variable for the script runtime but does not change the variable used in the URL before the request is sent. URL substitution uses environment, collection, or global variables, not local script variables.
Postman supports multiple variable scopes: global, environment, collection, and local (script). When Postman replaces variables like {{varName}} in a request, which scope does it check first?
Consider the order Postman uses to resolve variables for substitution in requests.
Postman resolves variables for substitution in this order (highest to lowest priority): local (script) variables, collection variables, environment variables, then global variables. Local variables set using pm.variables.set() in pre-request scripts do affect request variable substitution.