0
0
Postmantesting~10 mins

Form-data body in Postman - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test sends a POST request with form-data body to an API endpoint and verifies the response status and returned data.

Test Code - Postman Test Script
Postman
pm.test("POST request with form-data body", function () {
    pm.sendRequest({
        url: 'https://postman-echo.com/post',
        method: 'POST',
        header: {
            'Content-Type': 'application/x-www-form-urlencoded'
        },
        body: {
            mode: 'formdata',
            formdata: [
                { key: 'username', value: 'testuser', type: 'text' },
                { key: 'password', value: 'pass123', type: 'text' }
            ]
        }
    }, function (err, res) {
        pm.expect(err).to.be.null;
        pm.expect(res).to.have.property('code', 200);
        const jsonData = res.json();
        pm.expect(jsonData.form).to.have.property('username', 'testuser');
        pm.expect(jsonData.form).to.have.property('password', 'pass123');
    });
});
Execution Trace - 5 Steps
StepActionSystem StateAssertionResult
1Test startsPostman test runner is ready to execute the test script-PASS
2Sends POST request to https://postman-echo.com/post with form-data body containing username and passwordRequest is sent with Content-Type multipart/form-data and form fields username=testuser, password=pass123-PASS
3Receives response from serverResponse status code 200 OK, response body contains JSON with form data echoed backCheck response code is 200PASS
4Parse response JSON and verify form data fieldsResponse JSON contains form object with username and password keysAssert form.username equals 'testuser' and form.password equals 'pass123'PASS
5Test ends successfullyAll assertions passed, test marked as pass-PASS
Failure Scenario
Failing Condition: Response status code is not 200 or form data keys are missing or incorrect
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test verify after sending the POST request?
AResponse contains HTML content
BRequest method is GET
CResponse status is 200 and form-data fields are correctly echoed
DForm-data keys are missing
Key Result
Always verify both the response status code and the actual data returned when testing API requests with form-data bodies to ensure the server processes the data correctly.