QA Interview Hub · Knowledge base · Quizzes · Українська

Cypress › Retry-ability, waiting, timeouts

What timeouts does Cypress have and how do you override them?

Each Cypress command group has its own timeout, overridden by the timeout option on a command, in it or describe config, or in cypress.config. defaultCommandTimeout (4 s) applies to queries and assertions, requestTimeout (5 s) and responseTimeout (30 s) to the network, pageLoadTimeout (60 s) to cy.visit, taskTimeout (60 s) to cy.task. Only the one that fired is raised, because a global increase hides slowness.

Cypress · Waiting

A report takes 12 seconds to generate and get fails on the fourth. Raise the timeout for everything?

One slow screen breaks a test and the temptation is strong: raise defaultCommandTimeout in the config. Then every real failure waits longer and a performance problem hides. This lesson explains which timeouts Cypress has, what they apply to and how to change one without touching the rest.

How it works and why. Cypress has no single "general" timeout: each group of commands has its own, because they wait for different things. The defaults come from the configuration docs.

Which timer on which command

cy.visitpageLoadTimeout, 60 sget / should / clickdefaultCommandTimeout, 4 scy.wait('@alias')requestTimeout 5 s + responseTimeout 30 scy.tasktaskTimeout, 60 s
Figure 1. Each timer covers its own kind of waiting, so fix the one that actually fired.
TimeoutDefaultApplies to
defaultCommandTimeout4 squeries, assertions, actionability
requestTimeout5 suntil the request goes out (cy.wait)
responseTimeout30 sthe response (cy.request, cy.wait)
pageLoadTimeout60 scy.visit, cy.go, cy.reload
taskTimeout60 scy.task

The error message names the timeout that fired (for example "Timed out retrying after 4000ms"), so read it first instead of guessing. For cy.wait('@alias') two timers apply in sequence: first waiting for the request to start, then for the response. During cy.request, responseTimeout applies.

Example: where to override. From narrower to wider: a command, a block of tests, the config.

// 1. one command
cy.get('[data-cy=report]', { timeout: 15000 }).should('be.visible');

// 2. one describe or it
describe('slow reports', { defaultCommandTimeout: 10000 }, () => {
  it('generates a PDF', () => {
    cy.get('[data-cy=pdf]').should('exist');
  });
});

// 3. waiting for a request
cy.wait('@report', { responseTimeout: 60000 });

// 4. globally (the last resort): cypress.config.ts
// e2e: { defaultCommandTimeout: 6000 }

A targeted value is honest: it says that this particular action is slow. A global one hides slow places and lengthens every failure. If a screen is always slow, that is a reason to ask developers about performance, not about a timeout.

Limits and alternatives. A command timeout does not limit the whole test: by default Cypress imposes no single limit on a test, so a test can last the sum of all waits. Hangs are caught at the CI job level. A larger timeout does not cure flakiness, it only gives more time.

In Playwright:

There is a whole-test timeout (timeout, 30 s), a separate one for expect (5 s) and optional actionTimeout and navigationTimeout. The key difference: in Playwright the test is bounded as a whole, in Cypress by default it is not.

Common mistakes.

  • Raising defaultCommandTimeout globally because of one slow screen.
  • Changing the wrong timeout: a slow API response is handled by responseTimeout, not a get timeout.
  • Assuming Cypress will cut off a hung test: there is no per-test limit by default.

Check yourself

cy.visit fails after 60 s and cy.get('x') after 4 s. Why different numbers and what do you change if the screen itself is slow?

Answer

They are different timeouts: pageLoadTimeout for page load and defaultCommandTimeout for queries. For a slow element raise the timeout of that command only, not the global one.

Which timeouts bound cy.wait('@alias') and in what order do they apply?

Answer

Two, in sequence: requestTimeout (5 s) waits for the request to go out, responseTimeout (30 s) waits for the response.

In an interview. Junior: The main one is defaultCommandTimeout, 4 seconds for lookups and assertions. For the network there are requestTimeout and responseTimeout, for cy.visit pageLoadTimeout, for cy.task taskTimeout. I override with the timeout option on a command. Middle/Senior: I change only the timeout that fired, and in a targeted way: on a command, in a describe or it config. A global increase hides performance problems. Cypress has no per-test limit by default, so I catch hangs at the CI level.

More articles in this chapter