Auto-waiting
// 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
// ❌ 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
Assertion
A statement in a test that checks an expected condition holds. If it doesn't, the test fails. The core of every automated test.
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.
Retry Logic
Re-running a failing test or step automatically. Useful for taming flake from infrastructure issues — but can mask real bugs if used as a band-aid for genuinely flaky tests.
Learn more · JavaScript for QA
Chapter 6 · Lesson 4: How Automation Frameworks Interact With the DOM