0
0
Cypresstesting~20 mins

Assertion timeout customization in Cypress - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Assertion Timeout Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the test result with customized assertion timeout?

Consider this Cypress test snippet that checks if a button becomes visible within a custom timeout.

cy.get('#submit-btn', { timeout: 10000 }).should('be.visible')

Assuming the button appears after 8 seconds, what will be the test outcome?

Cypress
cy.get('#submit-btn', { timeout: 10000 }).should('be.visible')
ATest fails with a syntax error due to incorrect timeout usage.
BTest fails because the default timeout is 4 seconds, which is exceeded.
CTest passes because the button appears before the 10-second timeout.
DTest passes immediately without waiting for the button.
Attempts:
2 left
💡 Hint

Remember that the timeout option overrides the default wait time for the element.

assertion
intermediate
2:00remaining
Which assertion correctly sets a custom timeout for visibility check?

Choose the correct Cypress assertion that waits up to 5 seconds for an element with id login to be visible.

Acy.get('#login', { timeout: 5000 }).should('be.visible')
Bcy.get('#login').should({ timeout: 5000 }, 'be.visible')
Ccy.get('#login').should('be.visible', { timeout: 5000 })
Dcy.get('#login').should('be.visible').timeout(5000)
Attempts:
2 left
💡 Hint

Check where the timeout option is passed in Cypress commands.

🔧 Debug
advanced
2:00remaining
Why does this assertion timeout too early despite custom timeout?

Review this Cypress test code:

cy.get('#profile', { timeout: 10000 }).should('contain.text', 'User')

The element #profile appears after 9 seconds with text 'User Profile'. The test fails with a timeout error after 4 seconds. Why?

Cypress
cy.get('#profile', { timeout: 10000 }).should('contain.text', 'User')
AThe timeout option on <code>cy.get</code> applies only to element existence, not to assertion retries.
BThe default timeout for <code>should</code> assertions is 4 seconds and is not overridden by <code>cy.get</code> timeout.
CThe timeout option is ignored because <code>contain.text</code> is not a valid assertion.
DThe test fails because the text 'User' does not exactly match 'User Profile'.
Attempts:
2 left
💡 Hint

Consider how Cypress handles timeouts for commands versus assertions.

framework
advanced
2:00remaining
How to globally customize assertion timeout in Cypress?

Which configuration change globally sets the default assertion timeout to 8000 milliseconds in Cypress?

AAdd <code>assertionTimeout: 8000</code> in <code>cypress.json</code> root level.
BAdd <code>defaultCommandTimeout: 8000</code> in <code>cypress.config.js</code> under <code>e2e</code> section.
CAdd <code>defaultAssertionTimeout: 8000</code> in <code>cypress.config.js</code> under <code>e2e</code> section.
DAdd <code>timeout: 8000</code> in <code>package.json</code> under <code>scripts</code>.
Attempts:
2 left
💡 Hint

Check Cypress official docs for global timeout settings.

🧠 Conceptual
expert
2:00remaining
Why might increasing assertion timeout cause flaky tests?

Increasing assertion timeout can help tests wait longer for conditions. However, what is a common risk of setting very high assertion timeouts in Cypress tests?

ATests will always fail faster, causing more false negatives.
BAssertions will stop retrying and only check once immediately.
CCypress will ignore the timeout and use default values anyway.
DTests may become slower and mask real failures by waiting too long for conditions that never happen.
Attempts:
2 left
💡 Hint

Think about test speed and reliability trade-offs.