0
0
Cypresstesting~10 mins

Preserving state between tests 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 preserve cookies between tests in Cypress.

Cypress
beforeEach(() => {
  Cypress.Cookies.[1]('session_id')
});
Drag options to blanks, or click blank then click option'
ApreserveCookies
BclearCookies
CpreserveOnce
DgetCookie
Attempts:
3 left
💡 Hint
Common Mistakes
Using clearCookies instead of preserving cookies.
Trying to use getCookie which only reads cookies.
2fill in blank
medium

Complete the code to save local storage before each test.

Cypress
beforeEach(() => {
  cy.[1]('localStorage')
});
Drag options to blanks, or click blank then click option'
AsaveLocalStorage
BrestoreLocalStorage
CclearLocalStorage
DgetLocalStorage
Attempts:
3 left
💡 Hint
Common Mistakes
Using restoreLocalStorage before saving it.
Trying to clear local storage instead of saving.
3fill in blank
hard

Fix the error in the code to restore local storage after each test.

Cypress
afterEach(() => {
  cy.[1]('localStorage')
});
Drag options to blanks, or click blank then click option'
ArestoreLocalStorage
BsaveLocalStorage
CclearLocalStorage
DgetLocalStorage
Attempts:
3 left
💡 Hint
Common Mistakes
Using saveLocalStorage after the test instead of restoring.
Trying to clear local storage instead of restoring.
4fill in blank
hard

Fill both blanks to preserve cookies and local storage between tests.

Cypress
beforeEach(() => {
  Cypress.Cookies.[1]('session_id')
  cy.[2]('localStorage')
});
Drag options to blanks, or click blank then click option'
ApreserveOnce
BsaveLocalStorage
CclearCookies
DrestoreLocalStorage
Attempts:
3 left
💡 Hint
Common Mistakes
Using clearCookies which removes cookies instead of preserving.
Using restoreLocalStorage before saving local storage.
5fill in blank
hard

Fill all three blanks to preserve cookies, save local storage before tests, and restore local storage after tests.

Cypress
beforeEach(() => {
  Cypress.Cookies.[1]('auth_token')
  cy.[2]('localStorage')
});
afterEach(() => {
  cy.[3]('localStorage')
});
Drag options to blanks, or click blank then click option'
ApreserveOnce
BsaveLocalStorage
CrestoreLocalStorage
DclearCookies
Attempts:
3 left
💡 Hint
Common Mistakes
Using clearCookies which deletes cookies instead of preserving.
Mixing up save and restore commands for local storage.