0
0
Postmantesting~15 mins

Send request block in Postman - Build an Automation Script

Choose your learning style9 modes available
Send a POST request with JSON body and verify response status
Preconditions (3)
Step 1: Open Postman and create a new POST request
Step 2: Enter the URL https://api.example.com/login in the request URL field
Step 3: Select POST method
Step 4: Go to the Body tab and select raw and JSON format
Step 5: Enter the JSON body: {"username": "testuser", "password": "Test@123"}
Step 6: Click the Send button
Step 7: Observe the response status code and body
✅ Expected Result: Response status code is 200 and response body contains a token field
Automation Requirements - Postman/Newman
Assertions Needed:
Verify response status code is 200
Verify response body contains a non-empty token field
Best Practices:
Use environment variables for URL and credentials
Use test scripts in Postman to assert response
Avoid hardcoding sensitive data in the request body
Use descriptive names for requests and collections
Automated Solution
Postman
pm.test('Status code is 200', function () {
    pm.response.to.have.status(200);
});
pm.test('Response has token', function () {
    var jsonData = pm.response.json();
    pm.expect(jsonData.token).to.exist;
    pm.expect(jsonData.token).to.be.a('string').that.is.not.empty;
});

The first test checks if the response status code is exactly 200, which means the request was successful.

The second test parses the JSON response body and verifies that the token field exists, is a string, and is not empty. This confirms that the login was successful and a token was returned.

Using pm.test allows grouping assertions with clear descriptions. Parsing JSON with pm.response.json() is the standard way to access response data in Postman scripts.

Common Mistakes - 3 Pitfalls
Hardcoding the API URL and credentials directly in the request body
Not checking the response status code before accessing response body
Using incorrect assertion syntax like pm.expect(response.status).toBe(200)
Bonus Challenge

Now add data-driven testing with 3 different sets of user credentials to verify login success or failure.

Show Hint