Test Overview
This test checks if a cookie named session_id is set correctly after visiting the homepage. It then verifies the cookie value and deletes it to confirm removal.
This test checks if a cookie named session_id is set correctly after visiting the homepage. It then verifies the cookie value and deletes it to confirm removal.
describe('Cookie management test', () => { it('should set, verify, and clear a cookie', () => { cy.visit('https://example.com'); cy.setCookie('session_id', 'abc123'); cy.getCookie('session_id').should('have.property', 'value', 'abc123'); cy.clearCookie('session_id'); cy.getCookie('session_id').should('be.null'); }); });
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts | Test runner initialized, no browser opened yet | — | PASS |
| 2 | Browser opens and navigates to https://example.com | Homepage of example.com loaded in browser | — | PASS |
| 3 | Set cookie named 'session_id' with value 'abc123' | Cookie 'session_id=abc123' stored in browser | — | PASS |
| 4 | Get cookie 'session_id' and check its value | Cookie 'session_id' retrieved from browser | Verify cookie value equals 'abc123' | PASS |
| 5 | Clear cookie named 'session_id' | Cookie 'session_id' removed from browser | — | PASS |
| 6 | Get cookie 'session_id' and verify it is null | No cookie named 'session_id' found | Verify cookie is null (does not exist) | PASS |
session_id with value abc123?cy.setCookie(name, value).cy.setCookie with correct parameters.cy.setCookie('token', 'xyz789')
cy.getCookie('token').should('have.property', 'value', 'xyz789')cy.clearCookie()
auth_token cookie. Which Cypress approach correctly achieves this?cy.getCookie('auth_token').then(cookie => { cy.setCookie(cookie.name, cookie.value) }) after reload manually gets and sets the cookie again after reload, which preserves it correctly. Use cy.preserveCookie('auth_token') before reload is invalid syntax. Use cy.clearCookies() before reload to reset cookies clears cookies, which removes the token. Use cy.reload({ preserveCookies: true }) to keep cookies is not a valid reload option in Cypress.Pass the test and this pattern moves unknown