0
0
Cypresstesting~3 mins

Command timeout vs assertion timeout in Cypress - When to Use Which

Choose your learning style9 modes available
The Big Idea

Discover how smart waiting can save your tests from false failures and endless delays!

The Scenario

Imagine testing a website manually by clicking buttons and waiting for pages to load. Sometimes the page is slow, and you wait too long or give up too soon. You might miss errors or think the site is broken when it is just slow.

The Problem

Manually guessing how long to wait is frustrating and unreliable. You waste time waiting too long or get false failures by stopping too early. It's hard to know if a page or element is truly ready or just slow to respond.

The Solution

Using command timeout and assertion timeout in Cypress lets you control how long to wait for actions and checks. Command timeout waits for commands like clicks or loads, while assertion timeout waits for conditions like text to appear. This makes tests smarter and more reliable.

Before vs After
Before
cy.get('.button').click(); // no wait control
cy.contains('Success'); // no timeout control
After
cy.get('.button', { timeout: 10000 }).click();
cy.contains('Success', { timeout: 5000 }).should('be.visible');
What It Enables

It enables tests to patiently wait just the right amount of time, reducing false failures and speeding up test runs.

Real Life Example

When testing a slow-loading page, command timeout waits for the button to appear before clicking, and assertion timeout waits for confirmation text, so tests pass only when the app is truly ready.

Key Takeaways

Manual waiting is slow and unreliable.

Command timeout controls how long Cypress waits for commands.

Assertion timeout controls how long Cypress waits for conditions to be true.