describe('Cookie management test on example.com', () => {
beforeEach(() => {
cy.visit('https://example.com');
});
it('sets, verifies, and clears a cookie', () => {
// Set cookie
cy.setCookie('session_id', 'abc123');
// Verify cookie is set with correct value
cy.getCookie('session_id').should('have.property', 'value', 'abc123');
// Clear the cookie
cy.clearCookie('session_id');
// Verify cookie is removed
cy.getCookie('session_id').should('be.null');
});
});This test visits https://example.com before each test to ensure a fresh state.
It sets a cookie named session_id with value abc123 using cy.setCookie.
Then it verifies the cookie exists and has the correct value using cy.getCookie and should('have.property', 'value', 'abc123').
Next, it clears the cookie with cy.clearCookie.
Finally, it verifies the cookie no longer exists by asserting cy.getCookie('session_id').should('be.null').
This approach uses Cypress commands consistently and relies on Cypress automatic waiting, avoiding manual waits.