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.
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.
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'); }); });
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts: Prepare POST request with x-www-form-urlencoded body containing username and password | Postman environment ready to send request | - | PASS |
| 2 | Send POST request to https://postman-echo.com/post with Content-Type header set to application/x-www-form-urlencoded | Request sent, waiting for response | - | PASS |
| 3 | Receive response from server | Response received with status code 200 and JSON body | Check response status code is 200 | PASS |
| 4 | Parse JSON response body and verify form data contains username and password with correct values | Response JSON parsed: form data includes username='testuser' and password='testpass' | Assert form.username == 'testuser' and form.password == 'testpass' | PASS |
| 5 | Test completes successfully | All assertions passed, test finished | - | PASS |