In Cypress testing, what is the main difference between command timeout and assertion timeout?
Think about what Cypress waits for when running commands versus checking conditions.
Command timeout controls how long Cypress waits for a command like cy.get() to find an element or complete. Assertion timeout controls how long Cypress waits for an assertion like should('be.visible') to become true before failing the test.
Consider this Cypress code snippet:
cy.get('#submit-button', { timeout: 2000 }).click()If the element #submit-button does not appear within 2 seconds, what will happen?
Remember what the timeout option controls in cy.get().
The timeout option in cy.get() sets how long Cypress waits for the element to appear. If the element is not found within 2 seconds, Cypress throws a timeout error and fails the test.
Given this Cypress code:
cy.get('#status-message').should('contain', 'Success', { timeout: 5000 })What does the timeout: 5000 option do here?
Think about how Cypress retries assertions until they pass or timeout.
The timeout option inside should() sets how long Cypress waits and retries the assertion before failing. This helps with flaky UI updates that may take time.
Look at this Cypress test:
cy.get('#loading', { timeout: 1000 }).should('not.exist')The element #loading disappears after 3 seconds, but the test fails. Why?
Consider the difference between command timeout and assertion timeout.
The timeout: 1000 sets the command timeout for the entire chain including the assertion. Cypress finds the element quickly (since it exists initially) but retries the should('not.exist') for only up to 1 second. Since the element takes 3 seconds to disappear, the test times out and fails.
Which configuration snippet correctly sets a global command timeout of 10 seconds and a global assertion timeout of 7 seconds in Cypress?
Check Cypress official config property names for timeouts.
The correct Cypress config keys are defaultCommandTimeout for commands and defaultAssertionTimeout for assertions. Other keys are invalid and will be ignored or cause errors.