Auto-waiting

Automationbeginner

// Definition

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.

// Why it matters

Auto-waiting is the framework retrying an action until the element is actionable (visible, stable, enabled) instead of failing instantly. It's why modern tools (Cypress, Playwright) are less flaky than older ones — but only if you don't defeat it with hard sleeps or by asserting on the wrong signal.

// How to test

// Let the framework retry; don't bridge timing with sleeps
// ❌ defeats auto-waiting
cy.wait(2000); cy.get('[data-cy=row]').click()
// ✅ retries until the row exists & is actionable
cy.get('[data-cy=row]').should('be.visible').click()
// wait on the cause, not the clock
cy.intercept('GET', '/api/rows').as('rows')
cy.visit('/list'); cy.wait('@rows')

// Code Example

CypressAuto-wait beats hard-coded sleeps
TypeScript
// ❌ Brittle — wastes time and still flakes
cy.wait(5000);
cy.get('.toast').should('be.visible');

// ✅ Auto-waiting — retries until the assertion passes (or timeout)
cy.get('.toast', { timeout: 10000 }).should('be.visible');

// ✅ Wait for the network event you actually depend on
cy.intercept('POST', '/api/save').as('save');
cy.get('[data-testid=save]').click();
cy.wait('@save').its('response.statusCode').should('eq', 200);

// Common mistakes

  • Adding cy.wait(ms) "just in case", reintroducing flakiness
  • Asserting on an element that exists but isn't yet interactive
  • Disabling retries globally to "speed up" the suite

// Related terms

Learn more · JavaScript for QA

Chapter 6 · Lesson 4: How Automation Frameworks Interact With the DOM