0
0
Postmantesting~10 mins

Bearer token in Postman - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test sends an API request with a Bearer token for authorization. It verifies that the server accepts the token and returns a successful response.

Test Code - Postman Tests
Postman
pm.test("Status code is 200", function () {
    pm.response.to.have.status(200);
});

pm.test("Response contains expected data", function () {
    const jsonData = pm.response.json();
    pm.expect(jsonData).to.have.property('userId');
});
Execution Trace - 5 Steps
StepActionSystem StateAssertionResult
1Open Postman and create a new GET request to the API endpointPostman UI shows the request setup screen with URL field empty-PASS
2Set Authorization type to Bearer Token and enter the token valueAuthorization tab shows Bearer Token selected and token input filled-PASS
3Send the request to the serverPostman sends HTTP GET request with Authorization header: Bearer <token>-PASS
4Receive response from server with status code 200 and JSON bodyResponse tab shows status 200 OK and JSON data including userIdCheck that response status is 200PASS
5Run test script to verify response contains 'userId' propertyTest results panel shows test executionVerify response JSON has property 'userId'PASS
Failure Scenario
Failing Condition: Bearer token is missing, expired, or invalid causing server to reject authorization
Execution Trace Quiz - 3 Questions
Test your understanding
What does the Bearer token do in this test?
AIt encrypts the response data
BIt authorizes the request to access protected resources
CIt changes the request method to POST
DIt sets the content type to JSON
Key Result
Always verify that the Bearer token is correctly set and valid before sending API requests to avoid authorization failures.