Explicit Wait

Web Automationintermediate

// 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