0
0
Cypresstesting~10 mins

Data cleanup approaches 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 clear cookies after each test in Cypress.

Cypress
afterEach(() => {
  cy.[1]();
});
Drag options to blanks, or click blank then click option'
AclearCookies
BclearCookie
CclearCookiesAndLocalStorage
DclearAllCookies
Attempts:
3 left
💡 Hint
Common Mistakes
Using a command that only clears cookies but not local storage.
Using a non-existent Cypress command.
2fill in blank
medium

Complete the code to reset the database before each test using a custom Cypress task.

Cypress
beforeEach(() => {
  cy.task('[1]');
});
Drag options to blanks, or click blank then click option'
AcleanDatabase
BclearDb
CresetDb
DresetDatabase
Attempts:
3 left
💡 Hint
Common Mistakes
Using a task name that does not match the backend implementation.
Forgetting to define the task in the Cypress plugins file.
3fill in blank
hard

Fix the error in the code to delete a user via API after each test.

Cypress
afterEach(() => {
  cy.request('DELETE', '/api/users/[1]');
});
Drag options to blanks, or click blank then click option'
Auser_id
Buserid
Cid
DuserId
Attempts:
3 left
💡 Hint
Common Mistakes
Using snake_case or all lowercase instead of camelCase.
Using a generic 'id' which may not be recognized by the API.
4fill in blank
hard

Fill both blanks to clear local storage and session storage before each test.

Cypress
beforeEach(() => {
  cy.window().then(win => {
    win.[1]();
    win.[2]();
  });
});
Drag options to blanks, or click blank then click option'
AlocalStorage.clear
BsessionStorage.clear
CclearLocalStorage
DclearSessionStorage
Attempts:
3 left
💡 Hint
Common Mistakes
Using Cypress commands instead of window methods.
Forgetting to include parentheses to call the functions.
5fill in blank
hard

Fill all three blanks to create a custom command that resets test data by calling an API and clearing cookies.

Cypress
Cypress.Commands.add('resetTestData', () => {
  cy.request('[1]', '/api/reset');
  cy.[2]();
  cy.[3]();
});
Drag options to blanks, or click blank then click option'
APOST
BclearCookies
CclearLocalStorage
DGET
Attempts:
3 left
💡 Hint
Common Mistakes
Using GET instead of POST for the API call.
Mixing up the order of clearing storage.
Using non-existent Cypress commands.