0
0
Cypresstesting~20 mins

Data cleanup approaches in Cypress - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Data Cleanup Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Why is data cleanup important in automated tests?

Imagine you run automated tests that create users in a system. Why should you clean up this test data after the tests finish?

ATo make the test reports look nicer
BBecause cleaning data makes tests run faster
CTo avoid cluttering the database and causing false test results in future runs
DBecause Cypress requires data cleanup to start tests
Attempts:
2 left
💡 Hint

Think about how leftover data might affect later tests.

Predict Output
intermediate
2:00remaining
What is the output of this Cypress test cleanup code?

Consider this Cypress command that deletes a user by ID after a test:

afterEach(() => {
  cy.request('DELETE', '/api/users/123')
    .then((response) => {
      cy.log(response.status)
    })
})

What will be logged if the user is successfully deleted?

Cypress
afterEach(() => {
  cy.request('DELETE', '/api/users/123')
    .then((response) => {
      cy.log(response.status)
    })
})
A200
B404
C500
Dundefined
Attempts:
2 left
💡 Hint

HTTP 200 means success for DELETE requests.

assertion
advanced
2:00remaining
Which assertion correctly verifies test data cleanup?

You want to check that a user with ID 456 no longer exists after cleanup. Which Cypress assertion is correct?

Cypress
cy.request({ method: 'GET', url: '/api/users/456', failOnStatusCode: false })
  .its('status')
  .should(/* fill here */)
A.should('eq', 200)
B.should('be.null')
C.should('not.exist')
D.should('eq', 404)
Attempts:
2 left
💡 Hint

Think about the HTTP status code when a resource is not found.

🔧 Debug
advanced
2:00remaining
Why does this cleanup code fail to delete test data?

Look at this Cypress cleanup code snippet:

after(() => {
  return cy.request('DELETE', '/api/users/789')
})

Tests pass but data is not deleted. What is the likely cause?

ACypress cannot send DELETE requests
BThe after() hook runs after all tests, but the deletion request is asynchronous and not waited on
CThe user ID 789 does not exist, so deletion silently fails
DThe DELETE method is not supported by the API
Attempts:
2 left
💡 Hint

Consider how Cypress handles asynchronous commands in hooks.

framework
expert
2:30remaining
Which Cypress approach ensures reliable test data cleanup across multiple tests?

You have many tests creating users. You want to clean all test users after the test suite finishes. Which approach is best?

AUse an <code>after()</code> hook to send a single API request that deletes all test users by a shared tag
BUse <code>afterEach()</code> to delete users one by one after each test
CManually delete users in the UI after tests finish
DDo not clean data; rely on database resets between test runs
Attempts:
2 left
💡 Hint

Think about efficiency and reliability for large test suites.