Challenge - 5 Problems
Cookie Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2: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')
Attempts:
2 left
💡 Hint
Remember that Cypress commands like setCookie and getCookie work asynchronously and can be chained.
✗ Incorrect
The code sets a cookie named 'session_id' with value 'abc123'. Then it retrieves the cookie and asserts that its 'value' property equals 'abc123'. However, 'getCookie' is not a valid Cypress command; the correct command is 'cy.getCookie'.
❓ assertion
intermediate2: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?
Attempts:
2 left
💡 Hint
Check the properties of the cookie object returned by getCookie.
✗ Incorrect
The cookie object has properties like 'name' and 'value'. To verify the cookie named 'user' exists, check that the 'name' property equals 'user'.
🔧 Debug
advanced2: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')
Attempts:
2 left
💡 Hint
Check the Cypress documentation for clearCookies usage.
✗ Incorrect
The clearCookies command clears all cookies and does not accept any arguments. Passing a cookie name causes the command to ignore the argument and not clear specific cookies.
🧠 Conceptual
advanced2: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?
Attempts:
2 left
💡 Hint
Think about test isolation and repeatability.
✗ Incorrect
Clearing cookies before each test ensures no leftover data affects test results, making tests independent and reliable.
❓ framework
expert2: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.
Attempts:
2 left
💡 Hint
Remember Cypress commands are asynchronous and chaining vs separate calls matters.
✗ Incorrect
Option A correctly sets the cookie, reloads the page, then gets the cookie and asserts its 'value' property equals 'xyz'. The commands are properly sequenced without chaining incompatible commands.