0
0
Postmantesting~10 mins

POST request in Postman - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test sends a POST request to create a new user and verifies that the response status is 201 and the returned data matches the sent data.

Test Code - Postman
Postman
pm.test("Create user POST request", function () {
    const requestBody = {
        name: "John Doe",
        job: "Software Tester"
    };

    pm.sendRequest({
        url: "https://reqres.in/api/users",
        method: "POST",
        header: {
            "Content-Type": "application/json"
        },
        body: {
            mode: "raw",
            raw: JSON.stringify(requestBody)
        }
    }, function (err, res) {
        pm.expect(err).to.be.null;
        pm.expect(res).to.have.property('status', 201);
        const jsonData = res.json();
        pm.expect(jsonData).to.have.property('name', requestBody.name);
        pm.expect(jsonData).to.have.property('job', requestBody.job);
        pm.expect(jsonData).to.have.property('id');
        pm.expect(jsonData).to.have.property('createdAt');
    });
});
Execution Trace - 7 Steps
StepActionSystem StateAssertionResult
1Test startsPostman test runner is ready to execute the POST request test-PASS
2Sends POST request to https://reqres.in/api/users with JSON body {name: 'John Doe', job: 'Software Tester'}Request is sent over the network to the API server-PASS
3Receives response from serverResponse contains status code 201 and JSON body with created user dataCheck that error is nullPASS
4Verifies response status code is 201Response status code is 201 Createdpm.expect(res).to.have.property('status', 201)PASS
5Parses response JSON and verifies 'name' and 'job' match requestResponse JSON has 'name' = 'John Doe' and 'job' = 'Software Tester'pm.expect(jsonData).to.have.property('name', 'John Doe') and pm.expect(jsonData).to.have.property('job', 'Software Tester')PASS
6Verifies response JSON contains 'id' and 'createdAt' fieldsResponse JSON includes 'id' and 'createdAt' propertiespm.expect(jsonData).to.have.property('id') and pm.expect(jsonData).to.have.property('createdAt')PASS
7Test ends successfullyAll assertions passed, user creation verified-PASS
Failure Scenario
Failing Condition: Response status code is not 201 or response JSON does not match expected data
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test verify after sending the POST request?
AThat the response status code is 404
BThat the response body is empty
CThat the response status code is 201 and response data matches the request
DThat the request method is GET
Key Result
Always verify both the HTTP status code and the response body content to ensure the POST request succeeded and returned expected data.