Test Overview
This test sends a POST request with a JSON body to an API endpoint. It verifies that the API accepts the body format and returns a success status code.
This test sends a POST request with a JSON body to an API endpoint. It verifies that the API accepts the body format and returns a success status code.
pm.test("Body format matches API expectations", function () { const requestBody = { "username": "testuser", "password": "securePass123" }; pm.sendRequest({ url: pm.environment.get("apiUrl") + "/login", 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', 200); pm.expect(res.json()).to.have.property('token').that.is.a('string'); }); });
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts | Postman test runner is ready | - | PASS |
| 2 | Prepare JSON body with username and password | Request body is set as JSON string | - | PASS |
| 3 | Send POST request to API endpoint /login with JSON body and Content-Type header | Request sent to server | - | PASS |
| 4 | Receive response from API | Response received with status code and JSON body | Check no error in request | PASS |
| 5 | Assert response status code is 200 | Response status code is 200 | Status code equals 200 | PASS |
| 6 | Assert response JSON contains a token string | Response JSON has token property | Token property exists and is a string | PASS |
| 7 | Test ends with all assertions passed | Test report shows success | - | PASS |