0
0
Postmantesting~10 mins

JSON body in Postman - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test sends a POST request with a JSON body to an API endpoint and verifies the response status and content.

Test Code - PyTest
Postman
import requests
import json

def test_post_json_body():
    url = "https://api.example.com/users"
    headers = {"Content-Type": "application/json"}
    payload = {
        "name": "Alice",
        "email": "alice@example.com",
        "age": 30
    }
    response = requests.post(url, headers=headers, json=payload)
    assert response.status_code == 201
    response_json = response.json()
    assert response_json.get("id") is not None
    assert response_json.get("name") == "Alice"
Execution Trace - 6 Steps
StepActionSystem StateAssertionResult
1Test startsTest environment ready, no requests sent yet-PASS
2Sends POST request to https://api.example.com/users with JSON body {"name": "Alice", "email": "alice@example.com", "age": 30}Request sent, waiting for response-PASS
3Receives response with status code 201 and JSON body containing user dataResponse received: {"id": "12345", "name": "Alice", "email": "alice@example.com", "age": 30}Check response status code is 201PASS
4Parses response JSON and verifies 'id' field is presentResponse JSON parsedAssert 'id' field is not NonePASS
5Verifies 'name' field in response JSON equals 'Alice'Response JSON parsedAssert 'name' == 'Alice'PASS
6Test ends successfullyAll assertions passed-PASS
Failure Scenario
Failing Condition: Response status code is not 201 or 'id' field missing in response JSON
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test verify after sending the POST request?
AResponse status code is 200 and response JSON contains 'email'
BResponse status code is 201 and response JSON contains 'id' and correct 'name'
CResponse status code is 404 and response JSON is empty
DResponse status code is 500 and response JSON contains error message
Key Result
Always verify both the HTTP status code and the response body content to ensure the API behaves as expected when sending JSON data.