0
0
Postmantesting~15 mins

Why body format matches API expectations in Postman - Automation Benefits in Action

Choose your learning style9 modes available
Verify API accepts correct JSON body format
Preconditions (3)
Step 1: Open Postman and create a new POST request
Step 2: Set the request URL to the API endpoint
Step 3: In the Body tab, select 'raw' and choose 'JSON' format
Step 4: Enter the JSON body: {"username": "testuser", "password": "Pass123!"}
Step 5: Send the request
Step 6: Observe the response status code and body
✅ Expected Result: The API responds with status code 200 and a success message indicating the body format was accepted
Automation Requirements - Postman/Newman
Assertions Needed:
Response status code is 200
Response body contains success confirmation
Best Practices:
Use JSON format in request body matching API schema
Validate response status and body content
Use environment variables for endpoint URLs
Add descriptive test names and comments
Automated Solution
Postman
pm.test('Status code is 200', function () {
    pm.response.to.have.status(200);
});

pm.test('Response has success message', function () {
    const jsonData = pm.response.json();
    pm.expect(jsonData.message).to.eql('Login successful');
});

The first test checks that the API returns a 200 status code, meaning the request was successful.

The second test parses the JSON response and verifies that the 'message' field equals 'Login successful', confirming the API accepted the body format.

Using pm.response and pm.expect ensures we use Postman's built-in assertion methods for clarity and reliability.

Common Mistakes - 3 Pitfalls
{'mistake': 'Sending body as plain text instead of JSON', 'why_bad': 'API expects JSON format; sending plain text causes parsing errors and request failure', 'correct_approach': "Set body type to 'raw' and select 'JSON' in Postman before entering JSON content"}
Using incorrect field names or missing required fields in JSON body
Not verifying response status code before checking response body
Bonus Challenge

Now add data-driven testing with 3 different sets of username and password combinations

Show Hint