0
0
Postmantesting~10 mins

x-www-form-urlencoded body in Postman - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test sends a POST request with an x-www-form-urlencoded body to an API endpoint and verifies the response status and body content.

Test Code - Postman
Postman
pm.test("POST request with x-www-form-urlencoded body", function () {
    pm.sendRequest({
        url: 'https://postman-echo.com/post',
        method: 'POST',
        header: {
            'Content-Type': 'application/x-www-form-urlencoded'
        },
        body: {
            mode: 'urlencoded',
            urlencoded: [
                { key: 'username', value: 'testuser' },
                { key: 'password', value: 'testpass' }
            ]
        }
    }, 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', 'testpass');
    });
});
Execution Trace - 5 Steps
StepActionSystem StateAssertionResult
1Test starts: Prepare POST request with x-www-form-urlencoded body containing username and passwordPostman environment ready to send request-PASS
2Send POST request to https://postman-echo.com/post with Content-Type header set to application/x-www-form-urlencodedRequest sent, waiting for response-PASS
3Receive response from serverResponse received with status code 200 and JSON bodyCheck response status code is 200PASS
4Parse JSON response body and verify form data contains username and password with correct valuesResponse JSON parsed: form data includes username='testuser' and password='testpass'Assert form.username == 'testuser' and form.password == 'testpass'PASS
5Test completes successfullyAll assertions passed, test finished-PASS
Failure Scenario
Failing Condition: Response status code is not 200 or form data does not contain expected username and password
Execution Trace Quiz - 3 Questions
Test your understanding
What header is essential to set when sending an x-www-form-urlencoded POST request?
AContent-Type: application/json
BContent-Type: application/x-www-form-urlencoded
CAccept: text/html
DAuthorization: Bearer token
Key Result
Always set the correct Content-Type header when sending form data and verify the server echoes back the expected form fields to ensure the request was processed correctly.