Skip to content
IT glossary
TestingUpdated December 3, 2026

Cypress

A framework for automating tests of web applications in a browser. It can open pages, interact with the interface, and check whether the application behaves as expected.

What Cypress tests

Cypress runs JavaScript or TypeScript tests in a browser. An end-to-end (E2E) test opens a running application and follows a user journey, such as adding an item to a cart and checking that the total updates. A component test mounts part of the UI on its own. For example, it can check a date picker's keyboard controls without loading the full booking flow or connecting to a backend.

How commands and retries work

When the test calls cy.visit(), cy.get(), or .click(), Cypress queues commands and runs them in order. cy.get() doesn't immediately return a DOM element. It yields the matching elements to the next command in the chain when the query runs. Cypress commands aren't ordinary promises and shouldn't be used with await.

A chain such as cy.get(selector).should('be.visible') can re-run the query and assertion until the element is visible or the timeout expires. Actions work differently: .click() waits for the target to be ready, then clicks once. If a later assertion fails, Cypress doesn't keep clicking the button. Retrying the entire test is a separate feature.

Example: marking a task complete

it('marks an open task as complete', () => {
  cy.visit('/tasks/42')
  cy.get('[data-testid="complete-task"]').click()
  cy.get('[data-testid="task-status"]').should('have.text', 'Completed')
})

This example assumes a configured baseUrl and a task seeded in the open state. The test checks the status shown to the user, not the internal state of a component. The data-testid selectors won't break just because someone renames a CSS class or changes the button label.

Local development and CI

Use cypress open to run tests interactively and inspect the command log when a step fails. Use cypress run for unattended runs, such as on a pull request in CI. Set up the data each test needs so that a scenario passes on its own, not just after another test has run.

With cy.intercept(), a test can observe an application's HTTP request or supply a stubbed response. A stub is useful for testing how the UI handles a server error, but it doesn't verify that the backend produces that response. For critical flows, keep some E2E coverage against the real test backend.

What interviewers look for

You may be asked how to fix a test that uses cy.wait(2000) and still fails intermittently. If the requirement is visible in the UI, assert on that outcome and let Cypress retry the query. If the test needs to wait for a particular request, register an intercept with an alias before triggering the request, then use cy.wait('@alias'). Explain what you're waiting for and why: a response arriving doesn't necessarily mean the UI has finished updating.