0
0
Cypresstesting~10 mins

Data cleanup approaches in Cypress - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test verifies that after creating a new user via the UI, the test cleans up by deleting the user to keep the test environment clean.

Test Code - Cypress
Cypress
describe('User creation and cleanup', () => {
  it('creates a user and deletes it after test', () => {
    // Visit user creation page
    cy.visit('/users/new')

    // Fill user form
    cy.get('[data-cy=username]').type('testuser123')
    cy.get('[data-cy=email]').type('testuser123@example.com')
    cy.get('[data-cy=submit]').click()

    // Verify user is created
    cy.contains('User created successfully').should('be.visible')

    // Cleanup: delete the created user
    cy.visit('/users')
    cy.contains('testuser123').parent().find('[data-cy=delete]').click()
    cy.on('window:confirm', () => true) // Confirm deletion

    // Verify user is deleted
    cy.contains('testuser123').should('not.exist')
  })
})
Execution Trace - 10 Steps
StepActionSystem StateAssertionResult
1Test startsTest runner initialized, browser ready-PASS
2Browser opens and navigates to '/users/new'User creation page loaded with form fieldsURL contains '/users/new'PASS
3Find username input and type 'testuser123'Username field filled with 'testuser123'Input value is 'testuser123'PASS
4Find email input and type 'testuser123@example.com'Email field filled with 'testuser123@example.com'Input value is 'testuser123@example.com'PASS
5Find submit button and clickForm submitted, page processing-PASS
6Verify success message 'User created successfully' is visibleSuccess message displayed on pageMessage 'User created successfully' is visiblePASS
7Navigate to '/users' page to manage usersUsers list page loadedURL contains '/users'PASS
8Find user row containing 'testuser123' and click delete buttonDelete confirmation dialog appearsDelete button found for user 'testuser123'PASS
9Confirm deletion in browser dialogUser deletion processed-PASS
10Verify user 'testuser123' no longer exists in users listUser 'testuser123' removed from listUser 'testuser123' is not found on pagePASS
Failure Scenario
Failing Condition: User creation fails or user deletion does not remove the user
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test do after creating the user?
ALogs out of the application
BDeletes the created user to clean up
CCreates another user
DRefreshes the page
Key Result
Always clean up test data after creating it to keep the test environment stable and avoid side effects on other tests.