Why Cypress Does Not Need Explicit Waits Explained
Cypress automatically waits for commands and assertions to complete before moving on, so you don't need to add
explicit waits. It retries actions and checks until elements appear or conditions are met, making tests more reliable and simpler.Syntax
Cypress commands like cy.get() and cy.contains() include built-in waiting. You write commands normally without adding extra wait times.
Example parts:
cy.get(selector): Finds an element, waits until it exists..should(condition): Asserts a condition, retries until true or timeout.
javascript
cy.get('button').should('be.visible').click()
Example
This example shows Cypress waiting for a button to appear and be visible before clicking it, without any explicit wait commands.
javascript
describe('Cypress automatic wait example', () => { it('waits for button to appear and clicks it', () => { cy.visit('https://example.cypress.io') cy.get('button#delayed-button').should('be.visible').click() }) })
Output
Test passes if the button appears and is clicked; fails if button never appears within default timeout.
Common Pitfalls
New users often add cy.wait() with fixed times, which can slow tests and cause flakiness.
Instead, rely on Cypress's automatic waiting and assertions.
javascript
/* Wrong way: explicit wait */ cy.wait(5000) cy.get('button').click() /* Right way: automatic wait with assertion */ cy.get('button').should('be.visible').click()
Quick Reference
| Cypress Command | Automatic Wait Behavior |
|---|---|
| cy.get(selector) | Waits for element to exist in DOM and be actionable |
| cy.contains(text) | Waits for element containing text to appear |
| .should(condition) | Retries assertion until it passes or times out |
| .click() | Waits for element to be visible and enabled before clicking |
| cy.wait(time) | Explicit fixed wait (usually discouraged) |
Key Takeaways
Cypress commands automatically wait for elements and conditions before proceeding.
Avoid using fixed
cy.wait() to keep tests fast and reliable.Use assertions like
.should() to let Cypress retry until success.Automatic waiting reduces flaky tests caused by timing issues.
Trust Cypress's built-in retry and wait logic for smoother test writing.