Test Runner and Commands
The command chain end to end: what a spec enqueues, what each step yields, which steps retry, and what resets between tests. Most Cypress mistakes start here.
on this pageshowhide
explore
- Chain Construction15 questions
- Enqueue and Run Order5 questions
- Yielding and Closures5 questions
- Await and Plain Variables5 questions
- Retry-Ability9 questions
- Query and Action Steps4 questions
- Limits of Retrying5 questions
- Setup and Cleanup10 questions
- Hooks and State Reset5 questions
- Alias Lifetime5 questions
- Driving the Page10 questions
- Simulated User Events5 questions
- Pre-Action Readiness5 questions
questions
page 2 of 2How far should a Cypress 16 suite lean on `visibilityStrategy: 'legacy'`?
basics
~20 sTreat it as a short migration crutch, not a setting. It is deprecated and scheduled for removal, so use it to keep named specs green through one upgrade while you rewrite the assertions that depended on ancestor clipping.
In a Cypress suite, how far should `.trigger()` stand in for a real action command?
basics
~20 sCypress's .trigger() dispatches the named event and nothing else: no default browser action, no companion events, no focus change. Use it where the behaviour under test really is a listener, and keep real action commands wherever the browser default is the point.
How far should a Cypress suite go to work around not being able to store command results?
basics
~20 sOnly as far as the chain naturally goes. Treat deep callback nesting as a signal that the spec is discovering what it should already know, and move that knowledge into seeded data or a retried assertion.
When should a Cypress suite be allowed to set testIsolation: false?
basics
~20 sOnly for a small, read-only block where page loads dominate and no test mutates state another reads, approved on the condition that every test in it still passes under .only. Never at the root config.
Which shared Cypress helpers should be registered with Cypress.Commands.addQuery()?
basics
~20 sOnly helpers that are a pure, synchronous, repeatable read of the page or browser state. Anything that acts, awaits, or drives other cy commands must be a command — and a command stops the chain relinking after it.
In Cypress, how does an action command decide an element is still animating?
basics
~20 sIt measures rather than listens. On each retry Cypress records the element's position and compares the last two samples; if they are more than animationDistanceThreshold apart, five pixels by default, the element counts as animating.
In Cypress, why does a `.click()` report the event firing on the button's inner span?
basics
~20 sCypress fires at a coordinate, not at a node. The click lands on whatever element is topmost at that point, so a child covering the button's centre gets the event, and the Command Log names it. Focus still goes to the button.
In Cypress 16, what replaces the removed cy.end() command?
basics
~20 sNothing replaces it. cy.end() ended a chain by yielding null, which was never needed, because a Cypress chain is already terminated as soon as the next cy command starts a new one. In Cypress 16 you simply delete the calls.
What does Cypress's .as('total', { type: 'static' }) store that a default alias does not?
basics
~20 sA static alias stores the resolved value once, at the moment .as() runs, instead of the query chain that produced it. cy.get('@total') then returns that frozen value on every read rather than re-deriving it from the page.
Why does Cypress reject testIsolation: false on an it block but accept it on describe?
basics
~20 sBecause the browser-context reset happens at the boundary between tests, not inside one. Cypress resolves it per suite, so a per-test value would be ambiguous, and it errors that testIsolation can only be overridden from a suite-level override.
In Cypress, why does a `while` loop around `cy.get()` hang the spec instead of retrying?
basics
~20 sBecause the loop never gives control back. Cypress only starts running commands once the spec body finishes, so every iteration piles more commands onto the queue, the exit condition can never flip, and the browser eventually gives out.
In Cypress, why does a value returned from a .each() callback never reach the next command?
basics
~20 sCypress's .each() always yields back the array-like subject it was given, whatever the callback returns, and it deliberately breaks the subject link to any chain the callback started. Only returning exactly false means something: it ends the loop early.
Should a Cypress test behave differently when Cypress.currentRetry is greater than zero?
basics
~20 sAlmost never for anything that changes what is asserted. Branching on the attempt number makes the retry a different test, so a green second attempt no longer tells you the first failure was environmental. Extra diagnostics are the defensible exception.
showing 31–44 of 44