Explicit Wait
// Definition
Telling a test to wait for a specific condition before proceeding — an element to be visible, a request to complete, text to appear — rather than pausing a fixed number of seconds (an implicit/hard wait). Explicit waits are condition-based and resolve as soon as the condition is met; hard sleeps waste time and still flake.
// Why it matters
The explicit-vs-hard-wait distinction is the single most common flakiness fix in QA. A hard sleep(3000) is both slow (always waits the full time) and unreliable (3s isn't enough under load). An explicit wait on the real condition is fast and stable. Knowing the difference is foundational to writing non-flaky tests.
// How to test
// ❌ hard wait — slow AND still flaky under load
cy.wait(3000); cy.get('[data-cy=result]').click()
// ✅ explicit wait — on the actual condition, resolves as soon as it's true
cy.intercept('GET', '/api/search*').as('search')
cy.get('[data-cy=go]').click()
cy.wait('@search') // wait for the request
cy.get('[data-cy=result]').should('be.visible') // and the rendered result// Common mistakes
- Hard sleeps "to be safe" — they're the #1 source of slow, flaky suites
- Waiting on a proxy signal (a sleep) instead of the real cause (the request/render)
- Over-long global timeouts that hide genuinely slow pages
// Related terms
Auto-waiting
A framework feature that pauses an action until the target element is actionable (visible, enabled, stable). Eliminates most need for explicit sleeps and reduces flake.
Flaky Test
A test that passes and fails intermittently without any code changes, often caused by timing issues, shared state, async race conditions, or external dependencies. The single largest source of CI noise.
Timeout
A maximum duration allowed for an operation to complete before it is considered failed. In API and network testing: connection timeout (time to establish the TCP connection), read timeout (time to receive the full response after connecting), and total deadline (aggregate across all retry attempts). A timed-out request differs from a failed request — the status code, error type, and retry behaviour differ and must each be tested explicitly.