0
0
Cypresstesting~20 mins

Cookie management in Cypress - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Cookie Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this Cypress test snippet?
Consider the following Cypress test code that sets a cookie and then checks its value. What will be the assertion result?
Cypress
cy.setCookie('session_id', 'abc123')
  .getCookie('session_id')
  .should('have.property', 'value', 'abc123')
ATest passes because the cookie value matches 'abc123'.
BTest passes but the cookie value is undefined.
CTest fails because 'should' cannot check cookie properties.
DTest fails because 'getCookie' is not a valid Cypress command.
Attempts:
2 left
💡 Hint
Remember that Cypress commands like setCookie and getCookie work asynchronously and can be chained.
assertion
intermediate
2:00remaining
Which assertion correctly verifies a cookie named 'user' exists in Cypress?
You want to check if a cookie named 'user' exists after login. Which assertion is correct?
Acy.getCookie('user').should('exist')
Bcy.getCookie('user').should('have.property', 'name', 'user')
Ccy.getCookie('user').should('have.value', 'user')
Dcy.getCookie('user').should('contain', 'user')
Attempts:
2 left
💡 Hint
Check the properties of the cookie object returned by getCookie.
🔧 Debug
advanced
2:00remaining
Why does this Cypress test fail to clear cookies?
This test tries to clear cookies but fails. Identify the reason.
Cypress
cy.clearCookies('session_id')
cy.getCookie('session_id').should('not.exist')
AgetCookie cannot be chained after clearCookies.
BThe cookie name 'session_id' is invalid.
CclearCookies does not accept arguments; it clears all cookies only.
Dshould('not.exist') is not a valid assertion for cookies.
Attempts:
2 left
💡 Hint
Check the Cypress documentation for clearCookies usage.
🧠 Conceptual
advanced
2:00remaining
What is the best practice for managing cookies in Cypress tests to avoid flaky tests?
Which practice helps ensure cookie-related tests are reliable and isolated?
AClear all cookies before each test to start fresh.
BSet cookies only once before all tests run.
CAvoid clearing cookies to speed up tests.
DManually delete cookies using browser DevTools during tests.
Attempts:
2 left
💡 Hint
Think about test isolation and repeatability.
framework
expert
2:00remaining
Which Cypress command sequence correctly sets a cookie, reloads the page, and verifies the cookie persists?
Select the correct code snippet that sets a cookie named 'token' with value 'xyz', reloads the page, and asserts the cookie still exists with the correct value.
A
cy.setCookie('token', 'xyz')
cy.reload()
cy.getCookie('token').should('have.property', 'value', 'xyz')
B
cy.setCookie('token', 'xyz')
cy.reload()
cy.getCookie('token').should('equal', 'xyz')
C
cy.setCookie('token', 'xyz')
  .reload()
  .getCookie('token')
  .should('have.property', 'value', 'xyz')
D
cy.setCookie('token', 'xyz')
  .reload()
  .getCookie('token')
  .should('equal', 'xyz')
Attempts:
2 left
💡 Hint
Remember Cypress commands are asynchronous and chaining vs separate calls matters.