0
0
Cypresstesting~10 mins

Cookie management in Cypress - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to visit a page and clear all cookies.

Cypress
cy.visit('https://example.com')
cy.[1]()
Drag options to blanks, or click blank then click option'
AclearCookies
BclearCookies()
CclearCookiesAll
DclearCookiesAll()
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting parentheses after the command name.
Using a non-existent command like clearCookiesAll.
2fill in blank
medium

Complete the code to set a cookie named 'session_id' with value 'abc123'.

Cypress
cy.setCookie('[1]', 'abc123')
Drag options to blanks, or click blank then click option'
Atoken
Buser_id
Cauth
Dsession_id
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong cookie name like 'token' or 'auth'.
3fill in blank
hard

Fix the error in the code to get a cookie named 'user_token'.

Cypress
cy.getCookie([1]).should('exist')
Drag options to blanks, or click blank then click option'
Auser_token
B'user_token'
C"user_token"
DuserToken
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the cookie name without quotes causing a reference error.
Using a wrong cookie name like 'userToken'.
4fill in blank
hard

Fill both blanks to check that the cookie 'auth' has value 'true'.

Cypress
cy.getCookie('[1]').its('value').should('[2]', 'true')
Drag options to blanks, or click blank then click option'
Aauth
Bhave.property
Ceq
Dexist
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'exist' instead of 'eq' to check the cookie value.
Using 'have.property' which is incorrect here.
5fill in blank
hard

Fill all three blanks to clear a cookie named 'session', then verify it no longer exists.

Cypress
cy.clearCookie('[1]').then(() => {
  cy.getCookie('[2]').should('[3]')
})
Drag options to blanks, or click blank then click option'
Asession
Bsession_id
Cnot.exist
Dexist
Attempts:
3 left
💡 Hint
Common Mistakes
Using different cookie names in clear and getCookie calls.
Using 'exist' instead of 'not.exist' to check absence.