0
0
Postmantesting~20 mins

Why pre-request scripts prepare data in Postman - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Pre-request Script Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Purpose of Pre-request Scripts in Postman

Why do we use pre-request scripts in Postman before sending an API request?

ATo generate the final test report after all requests run
BTo validate the response data after the request is sent
CTo set or modify variables and prepare data needed for the request execution
DTo automatically retry failed requests without user input
Attempts:
2 left
💡 Hint

Think about what needs to happen before sending a request to ensure it has the right data.

Predict Output
intermediate
1:30remaining
Output of Pre-request Script Variable Setting

What will be the value of the variable authToken after running this pre-request script in Postman?

Postman
pm.environment.set('authToken', 'abc123');
pm.environment.set('authToken', pm.environment.get('authToken') + 'XYZ');
A"abc123XYZ"
B"abc123"
Cundefined
D"XYZ"
Attempts:
2 left
💡 Hint

Look at how the variable is updated by appending a string.

assertion
advanced
2:00remaining
Correct Assertion for Pre-request Script Variable

Which assertion correctly checks that the variable sessionId is set and not empty in a Postman test script?

Postman
const sessionId = pm.environment.get('sessionId');
Apm.expect(sessionId).to.be.false;
Bpm.expect(sessionId).to.equal(undefined);
Cpm.expect(sessionId).to.be.null;
Dpm.expect(sessionId).to.be.a('string').and.not.empty;
Attempts:
2 left
💡 Hint

Think about how to check a variable is a non-empty string.

🔧 Debug
advanced
1:30remaining
Debugging a Pre-request Script Error

What error will this pre-request script cause when run in Postman?

Postman
pm.environment.set('count', count + 1);
ATypeError: Cannot read property 'set' of undefined
BReferenceError: count is not defined
CSyntaxError: Unexpected token '+'
DNo error, sets count to 1
Attempts:
2 left
💡 Hint

Check if the variable count is defined before using it.

framework
expert
2:30remaining
Best Practice for Dynamic Data Preparation in Pre-request Scripts

Which approach best ensures dynamic data like timestamps or tokens are fresh and correctly used in Postman pre-request scripts?

AGenerate or fetch dynamic data inside the pre-request script and set it as environment variables before the request runs
BHardcode dynamic data values in the request headers and update manually before each run
CUse test scripts after the request to modify dynamic data for the next request
DStore dynamic data only in global variables without updating them in pre-request scripts
Attempts:
2 left
💡 Hint

Think about when and where dynamic data should be created to be used in the request.