0
0
Cypresstesting~10 mins

Cookie management in Cypress - Test Execution Trace

Choose your learning style9 modes available
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.

Test Code - Cypress
Cypress
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');
  });
});
Execution Trace - 6 Steps
StepActionSystem StateAssertionResult
1Test startsTest runner initialized, no browser opened yet-PASS
2Browser opens and navigates to https://example.comHomepage of example.com loaded in browser-PASS
3Set cookie named 'session_id' with value 'abc123'Cookie 'session_id=abc123' stored in browser-PASS
4Get cookie 'session_id' and check its valueCookie 'session_id' retrieved from browserVerify cookie value equals 'abc123'PASS
5Clear cookie named 'session_id'Cookie 'session_id' removed from browser-PASS
6Get cookie 'session_id' and verify it is nullNo cookie named 'session_id' foundVerify cookie is null (does not exist)PASS
Failure Scenario
Failing Condition: Cookie 'session_id' is not set or has wrong value after setting
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test verify after setting the cookie?
AThe cookie named 'session_id' is deleted immediately
BThe page title contains 'session_id'
CThe cookie named 'session_id' has the value 'abc123'
DThe cookie named 'user_id' has the value 'abc123'
Key Result
Always verify cookie values after setting them and confirm removal after clearing to ensure correct cookie management in tests.