Test Overview
This test sends a GET request to a sample API endpoint and verifies that the response body contains the expected data.
This test sends a GET request to a sample API endpoint and verifies that the response body contains the expected data.
describe('API Response Body Assertion', () => { it('should verify the response body contains expected user data', () => { cy.request('https://jsonplaceholder.typicode.com/users/1') .then((response) => { expect(response.status).to.equal(200); expect(response.body).to.have.property('id', 1); expect(response.body).to.have.property('username', 'Bret'); }); }); });
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts | Cypress test runner initialized | - | PASS |
| 2 | Sends GET request to https://jsonplaceholder.typicode.com/users/1 | Request sent, waiting for response | - | PASS |
| 3 | Receives response with status 200 and JSON body | Response received with user data | Check response.status equals 200 | PASS |
| 4 | Asserts response body has property 'id' with value 1 | Response body contains user object | response.body.id === 1 | PASS |
| 5 | Asserts response body has property 'username' with value 'Bret' | Response body contains user object | response.body.username === 'Bret' | PASS |
| 6 | Test ends successfully | All assertions passed | - | PASS |