Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Principle:Cypress io Cypress DOM Assertion and Interaction

From Leeroopedia
Revision as of 18:02, 16 February 2026 by Admin (talk | contribs) (Auto-imported from principles/Cypress_io_Cypress_DOM_Assertion_and_Interaction.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Sources
Domains Testing, Browser_Automation
Last Updated 2026-02-12 00:00 GMT

Overview

A retry-based mechanism for querying DOM elements, performing user actions, and asserting on state that automatically retries until conditions are met or a timeout is reached.

Description

DOM assertion and interaction is the core testing primitive in Cypress. Unlike traditional test frameworks where assertions fail immediately, Cypress queries and assertions automatically retry. When cy.get('.btn') does not find an element, it retries the query until the element appears or the timeout expires. When cy.should('be.visible') fails, it retries the preceding query and re-evaluates the assertion.

Actions like click() and type() include actionability checks: they wait for the element to be visible, not disabled, not covered, and not animating before performing the action. This eliminates the flakiness common in browser automation.

Usage

Use this principle in every component and E2E test when interacting with rendered DOM elements. The retry-based approach applies to all cy.get, cy.contains, cy.should, and action commands.

Theoretical Basis

Retry Algorithm:
1. Execute query/assertion
2. If passes → proceed to next command
3. If fails and timeout not reached → wait requestAnimationFrame → retry from step 1
4. If fails and timeout reached → fail test with last error

Actionability Checks (before click/type):
- Element is visible (not display:none, visibility:hidden, etc.)
- Element is not disabled
- Element is not covered by another element
- Element is not animating (position stable between frames)
- Element scrolled into view

Related Pages

Implemented By

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment