Test Overview
This test sends a POST request with form-data body to an API endpoint and verifies the response status and returned data.
This test sends a POST request with form-data body to an API endpoint and verifies the response status and returned data.
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'); }); });
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts | Postman test runner is ready to execute the test script | - | PASS |
| 2 | Sends POST request to https://postman-echo.com/post with form-data body containing username and password | Request is sent with Content-Type multipart/form-data and form fields username=testuser, password=pass123 | - | PASS |
| 3 | Receives response from server | Response status code 200 OK, response body contains JSON with form data echoed back | Check response code is 200 | PASS |
| 4 | Parse response JSON and verify form data fields | Response JSON contains form object with username and password keys | Assert form.username equals 'testuser' and form.password equals 'pass123' | PASS |
| 5 | Test ends successfully | All assertions passed, test marked as pass | - | PASS |