Bird
Raised Fist0
Cypresstesting~20 mins

Command timeout vs assertion timeout in Cypress - Practice Questions

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Timeout Mastery in Cypress
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Difference between command timeout and assertion timeout in Cypress

In Cypress testing, what is the main difference between command timeout and assertion timeout?

ACommand timeout is how long Cypress waits for a command to complete; assertion timeout is how long Cypress waits for an assertion to pass before failing.
BCommand timeout is how long Cypress waits for an assertion to pass; assertion timeout is how long Cypress waits for a command to complete.
CCommand timeout and assertion timeout are the same and used interchangeably in Cypress.
DCommand timeout only applies to network requests; assertion timeout only applies to UI element visibility.
Attempts:
2 left
💡 Hint

Think about what Cypress waits for when running commands versus checking conditions.

❓ Predict Output
intermediate
1:30remaining
What happens when command timeout is exceeded?

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?

AThe test will skip the click and continue without error.
BThe test will wait indefinitely until the element appears and then click it.
CThe test will fail immediately without waiting.
DThe test will fail with a timeout error after 2 seconds because the element was not found.
Attempts:
2 left
💡 Hint

Remember what the timeout option controls in cy.get().

❓ Predict Output
advanced
2:00remaining
Assertion timeout effect on flaky tests

Given this Cypress code:

cy.get('#status-message').should('contain', 'Success', { timeout: 5000 })

What does the timeout: 5000 option do here?

AIt sets the command timeout for <code>cy.get()</code> to 5 seconds, ignoring assertion wait time.
BIt makes Cypress wait 5 seconds before running the assertion once.
CIt makes Cypress wait up to 5 seconds for the assertion to pass before failing the test.
DIt causes Cypress to retry the entire test for 5 seconds if the assertion fails.
Attempts:
2 left
💡 Hint

Think about how Cypress retries assertions until they pass or timeout.

🔧 Debug
advanced
2:00remaining
Why does this test fail despite element appearing?

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?

ABecause assertion timeout is not set, Cypress never retries the assertion.
BBecause the command timeout is 1 second, Cypress stops waiting before the element disappears.
CBecause <code>should('not.exist')</code> does not wait for the element to disappear.
DBecause the element <code>#loading</code> is never found initially.
Attempts:
2 left
💡 Hint

Consider the difference between command timeout and assertion timeout.

❓ framework
expert
2:30remaining
Configuring global command and assertion timeouts in Cypress

Which configuration snippet correctly sets a global command timeout of 10 seconds and a global assertion timeout of 7 seconds in Cypress?

Amodule.exports = { e2e: { defaultCommandTimeout: 10000, defaultAssertionTimeout: 7000 } }
Bmodule.exports = { e2e: { commandTimeout: 10000, assertionTimeout: 7000 } }
Cmodule.exports = { e2e: { defaultCommandTimeout: 10000, waitForAssertionsTimeout: 7000 } }
Dmodule.exports = { e2e: { defaultCommandTimeout: 10000, defaultTimeoutAssertions: 7000 } }
Attempts:
2 left
💡 Hint

Check Cypress official config property names for timeouts.

Practice

(1/5)
1. What is the main difference between command timeout and assertion timeout in Cypress?
easy
A. Command timeout is for API calls; assertion timeout is for UI rendering.
B. Command timeout waits for page load; assertion timeout waits for network requests.
C. Command timeout waits for actions like finding elements; assertion timeout waits for checks like visibility.
D. Command timeout waits for assertions; assertion timeout waits for commands.

Solution

  1. Step 1: Understand command timeout purpose

    Command timeout is the time Cypress waits to find or interact with elements before failing.
  2. Step 2: Understand assertion timeout purpose

    Assertion timeout is the time Cypress waits for conditions like visibility or text to become true in assertions.
  3. Final Answer:

    Command timeout waits for actions like finding elements; assertion timeout waits for checks like visibility. -> Option C
  4. Quick Check:

    Command timeout vs assertion timeout = Command timeout waits for actions like finding elements; assertion timeout waits for checks like visibility. [OK]
Hint: Command = action wait, Assertion = check wait [OK]
Common Mistakes:
  • Confusing command timeout with page load timeout
  • Thinking assertion timeout waits for commands
  • Mixing up API calls with UI element waits
2. Which of the following is the correct way to set a command timeout of 10 seconds in Cypress?
easy
A. cy.get('button', { timeout: 10000 })
B. cy.get('button').timeout(10000)
C. cy.get('button').setTimeout(10000)
D. cy.get('button').waitTimeout(10000)

Solution

  1. Step 1: Recall Cypress command timeout syntax

    Timeout for commands like cy.get() is set by passing an options object with timeout in milliseconds.
  2. Step 2: Check each option for correct syntax

    Only cy.get('button', { timeout: 10000 }) uses the correct syntax. The others use invalid methods.
  3. Final Answer:

    cy.get('button', { timeout: 10000 }) -> Option A
  4. Quick Check:

    Command timeout syntax = cy.get('button', { timeout: 10000 }) [OK]
Hint: Timeout is an option object in commands [OK]
Common Mistakes:
  • Using non-existent methods like .timeout()
  • Passing timeout as a separate method
  • Confusing assertion timeout syntax with command timeout
3. Consider this Cypress code snippet:
cy.get('#submit', { timeout: 5000 }).click();
cy.get('#message').should('be.visible', { timeout: 10000 });

What happens if the #submit button appears after 6 seconds and the #message appears after 8 seconds?
medium
A. Test fails at clicking #submit but passes the visibility check for #message.
B. Test passes both clicking #submit and visibility check for #message.
C. Test fails both clicking #submit and visibility check for #message.
D. Test passes clicking #submit but fails visibility check for #message.

Solution

  1. Step 1: Analyze command timeout for #submit

    The command timeout is 5000 ms (5 seconds). The button appears after 6 seconds, which is too late, so the click command fails.
  2. Step 2: Analyze assertion timeout for #message

    The assertion timeout is 10000 ms (10 seconds). The message appears after 8 seconds, which is within timeout, so the assertion passes.
  3. Final Answer:

    Test fails at clicking #submit but passes the visibility check for #message. -> Option A
  4. Quick Check:

    Command timeout too short, assertion timeout sufficient = Test fails at clicking #submit but passes the visibility check for #message. [OK]
Hint: Command timeout limits action wait; assertion timeout limits check wait [OK]
Common Mistakes:
  • Assuming both timeouts behave the same
  • Ignoring timeout values in options
  • Thinking assertion timeout affects commands
4. You wrote this Cypress test:
cy.get('.loading', { timeout: 3000 }).should('not.exist');

But the test fails because the element disappears after 5 seconds. What is the best fix?
medium
A. Increase the command timeout to more than 5000 ms.
B. Change should('not.exist') to should('be.visible').
C. Add a cy.wait(5000) before the assertion.
D. Increase the assertion timeout to more than 5000 ms.

Solution

  1. Step 1: Identify what is being waited on

    The test waits for the element to disappear, which is an assertion (should('not.exist')).
  2. Step 2: Adjust the correct timeout

    The command timeout controls finding the element, but the assertion timeout controls waiting for the condition. Since the element disappears after 5 seconds, increase assertion timeout beyond 5000 ms.
  3. Final Answer:

    Increase the assertion timeout to more than 5000 ms. -> Option D
  4. Quick Check:

    Assertion timeout controls condition wait = Increase the assertion timeout to more than 5000 ms. [OK]
Hint: Wait for condition? Increase assertion timeout [OK]
Common Mistakes:
  • Increasing command timeout instead of assertion timeout
  • Using fixed wait instead of timeout adjustment
  • Changing assertion logic incorrectly
5. You want to test a slow-loading modal that appears after clicking a button. The button may take up to 4 seconds to appear, and the modal may take up to 7 seconds to become visible. Which is the best way to set timeouts in Cypress?
hard
A. Use cy.get('button').click({ timeout: 7000 }) and cy.get('.modal').should('be.visible', { timeout: 4000 }).
B. Use cy.get('button', { timeout: 5000 }).click() and cy.get('.modal').should('be.visible', { timeout: 8000 }).
C. Use cy.get('button', { timeout: 3000 }).click() and cy.get('.modal').should('be.visible', { timeout: 3000 }).
D. Use cy.get('button').click() and cy.get('.modal').should('be.visible') with no timeouts set.

Solution

  1. Step 1: Set command timeout for button appearance

    The button may appear after up to 4 seconds, so set command timeout slightly higher (5000 ms) to allow finding it.
  2. Step 2: Set assertion timeout for modal visibility

    The modal may take up to 7 seconds to appear, so set assertion timeout higher (8000 ms) to wait for visibility.
  3. Final Answer:

    Use cy.get('button', { timeout: 5000 }).click() and cy.get('.modal').should('be.visible', { timeout: 8000 }). -> Option B
  4. Quick Check:

    Command timeout for action, assertion timeout for condition = Use cy.get('button', { timeout: 5000 }).click() and cy.get('.modal').should('be.visible', { timeout: 8000 }). [OK]
Hint: Set command timeout for element, assertion timeout for checks [OK]
Common Mistakes:
  • Swapping timeout values between command and assertion
  • Setting timeouts too low causing flaky tests
  • Not setting timeouts causing premature failures
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard