DYou cannot control request execution based on variables.
✗ Incorrect
Use an if condition in the Tests tab to call setNextRequest() only when the variable is true.
What is the default behavior if you do NOT use setNextRequest() in a collection run?
AOnly the first request runs.
BRequests run randomly.
CRequests run in the order they appear in the collection.
DThe collection run stops immediately.
✗ Incorrect
By default, Postman runs requests in the order they are listed in the collection.
Explain how setNextRequest() can be used to control the flow of requests in a Postman collection.
Think about how you decide which request runs next after one finishes.
You got /4 concepts.
Describe a scenario where you would use postman.setNextRequest() to skip some requests.
Imagine you only want to continue if a test passes.
You got /4 concepts.
Practice
(1/5)
1. What is the main purpose of pm.setNextRequest() in Postman?
easy
A. To decide which request runs next based on a condition
B. To send the current request multiple times automatically
C. To stop the entire collection run immediately
D. To reset all environment variables to default values
Solution
Step 1: Understand the function of pm.setNextRequest()
This function controls the flow of requests by specifying which request should run next.
Step 2: Compare with other options
Options B, C, and D describe different actions not related to controlling the next request.
Final Answer:
To decide which request runs next based on a condition -> Option A
Quick Check:
pm.setNextRequest() controls next request execution [OK]
Hint: Remember: setNextRequest controls the next request flow [OK]
Common Mistakes:
Thinking it repeats the current request
Confusing it with stopping the collection run
Assuming it resets variables
2. Which of the following is the correct syntax to set the next request named "Login" in a Postman test script?
easy
A. pm.setNextRequest(Login);
B. pm.setNextRequest("Login");
C. pm.setNextRequest('Login');
D. pm.setNextRequest(Login')
Solution
Step 1: Check the syntax for string argument
The request name must be passed as a string in quotes. Both single or double quotes are valid, but must be paired correctly.
Step 2: Identify correct option
pm.setNextRequest("Login"); uses double quotes correctly. pm.setNextRequest('Login'); also uses single quotes correctly. Both are valid syntaxes. pm.setNextRequest(Login); lacks quotes, causing a syntax error. pm.setNextRequest(Login') has mismatched quotes.
Final Answer:
pm.setNextRequest("Login"); -> Option B
Quick Check:
Request name must be a quoted string [OK]
Hint: Always quote request names in setNextRequest() [OK]
Common Mistakes:
Forgetting quotes around request name
Mismatched or missing quotes
Omitting semicolon at line end
3. Consider this test script in Postman after a request named "CheckStatus":
C. pm.setNextRequest cannot be used inside if statements
D. Using assignment (=) instead of comparison (===) in the if condition
Solution
Step 1: Identify the if condition error
The condition uses single equals (=), which assigns 200 to pm.response.code instead of comparing it.
Step 2: Understand consequences
This causes a bug: the if condition always evaluates to true, and response code is overwritten.
Final Answer:
Using assignment (=) instead of comparison (===) in the if condition -> Option D
Quick Check:
Use === for comparison, not = [OK]
Hint: Use === for comparison, not = assignment [OK]
Common Mistakes:
Confusing = with === in conditions
Removing quotes from request names
Thinking setNextRequest can't be conditional
5. You want to create a Postman flow where if a variable userExists is true, the next request is "GetUserData", else the flow stops. Which script correctly implements this in the test tab?
hard
A. if (pm.variables.get('userExists') === true) {
pm.setNextRequest('GetUserData');
} else {
pm.setNextRequest(null);
}
B. if (pm.variables.get('userExists') == 'true') {
pm.setNextRequest('GetUserData');
} else {
pm.setNextRequest('Stop');
}
C. if (pm.variables.get('userExists')) {
pm.setNextRequest('GetUserData');
} else {
pm.setNextRequest(null);
}
D. if (pm.variables.get('userExists') === 'true') {
pm.setNextRequest('GetUserData');
} else {
pm.setNextRequest(null);
}
Solution
Step 1: Understand variable type and condition
pm.variables.get returns a string or boolean depending on how set. Using it directly in if checks truthiness correctly.
Step 2: Check stopping the flow
Setting pm.setNextRequest(null) stops the collection run, which matches the requirement to stop if userExists is false.
Step 3: Evaluate options
if (pm.variables.get('userExists')) {
pm.setNextRequest('GetUserData');
} else {
pm.setNextRequest(null);
} uses direct truthiness check and null to stop, which is correct. Options A and C compare strictly to boolean or string which may fail if variable type differs. if (pm.variables.get('userExists') == 'true') {
pm.setNextRequest('GetUserData');
} else {
pm.setNextRequest('Stop');
} tries to set next request to 'Stop' which is not a request name and won't stop the flow.
Final Answer:
if (pm.variables.get('userExists')) {
pm.setNextRequest('GetUserData');
} else {
pm.setNextRequest(null);
} -> Option C
Quick Check:
Use truthy check and null to stop flow [OK]
Hint: Use null in setNextRequest to stop flow [OK]
Common Mistakes:
Comparing variable to string 'true' instead of boolean
Setting next request to a non-existent name to stop