Bird
Raised Fist0
Cypresstesting~20 mins

Retry-ability of commands in Cypress - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Retry Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
What is the output of this Cypress test snippet?

Consider this Cypress test code that tries to find a button and click it:

cy.get('button.submit').click()

If the button is not immediately present, what will Cypress do?

Cypress
cy.get('button.submit').click()
ACypress retries the <code>click</code> command multiple times but does not retry <code>get</code>.
BCypress immediately fails the test if the button is not found on the first try.
CCypress retries the <code>get</code> command until the button appears or timeout is reached, then clicks it.
DCypress waits for 5 seconds and then clicks the button regardless of presence.
Attempts:
2 left
💡 Hint

Think about how Cypress handles commands that query elements.

❓ assertion
intermediate
2:00remaining
Which assertion will Cypress retry automatically?

Given this code snippet:

cy.get('.message').should('contain', 'Success')

Which statement about the assertion is true?

Cypress
cy.get('.message').should('contain', 'Success')
ANeither <code>get</code> nor <code>should</code> are retried; test fails immediately if not found.
BCypress retries only the <code>get</code> command, but the assertion runs once immediately.
CCypress retries only the <code>should</code> assertion, not the <code>get</code> command.
DCypress retries the <code>get</code> and the <code>should</code> assertion until the text appears or timeout.
Attempts:
2 left
💡 Hint

Remember how Cypress handles chained commands and assertions.

🔧 Debug
advanced
2:00remaining
Why does this Cypress test fail despite retry-ability?

Look at this test code:

cy.get('#loadButton').click()
cy.get('#result').should('have.text', 'Loaded')

The test fails because #result does not have the expected text. Why?

Cypress
cy.get('#loadButton').click()
cy.get('#result').should('have.text', 'Loaded')
ABecause <code>click()</code> is not retried, the button might not have triggered loading before the assertion runs.
BBecause Cypress commands run asynchronously, the assertion runs before the click completes.
CBecause <code>get('#result')</code> does not retry, it fails if element is not present immediately.
DBecause <code>should('have.text')</code> does not retry, it checks only once immediately.
Attempts:
2 left
💡 Hint

Think about what Cypress retries and what it does not.

🧠 Conceptual
advanced
2:00remaining
Which Cypress command does NOT have built-in retry-ability?

Choose the command that Cypress does NOT retry automatically when it fails.

Acy.click()
Bcy.get(selector)
Ccy.contains(text)
Dcy.should('be.visible')
Attempts:
2 left
💡 Hint

Consider which commands are queries/assertions and which are actions.

❓ framework
expert
2:00remaining
How can you customize retry-ability timeout for a specific Cypress command?

You want to increase the time Cypress retries a get command before failing. Which option correctly sets a custom timeout for just that command?

Acy.get('.item').timeout(10000)
Bcy.get('.item', { timeout: 10000 })
Ccy.get('.item').setTimeout(10000)
Dcy.get('.item').retryTimeout = 10000
Attempts:
2 left
💡 Hint

Check Cypress docs for command options syntax.

Practice

(1/5)
1. What does retry-ability in Cypress help with during test execution?
easy
A. Automatically waiting for elements or conditions before proceeding
B. Skipping tests that take too long to run
C. Running tests in parallel on multiple browsers
D. Generating test data automatically

Solution

  1. Step 1: Understand retry-ability concept

    Retry-ability means Cypress waits and retries commands until the element or condition is met or timeout occurs.
  2. Step 2: Identify what retry-ability helps with

    This automatic waiting avoids flaky tests caused by timing issues, ensuring tests proceed only when ready.
  3. Final Answer:

    Automatically waiting for elements or conditions before proceeding -> Option A
  4. Quick Check:

    Retry-ability = Automatic wait [OK]
Hint: Retry-ability means Cypress waits automatically for conditions [OK]
Common Mistakes:
  • Confusing retry-ability with parallel test execution
  • Thinking retry-ability skips tests
  • Assuming retry-ability generates test data
2. Which of the following Cypress command patterns correctly uses retry-ability?
easy
A. cy.wait(5000).get('.btn').click()
B. cy.get('.btn').click()
C. cy.click('.btn')
D. cy.get('.btn').should('be.visible').click()

Solution

  1. Step 1: Identify retry-ability usage

    Retry-ability works with commands like get combined with should assertions that retry until condition is true.
  2. Step 2: Check each option

    cy.get('.btn').should('be.visible').click() uses get with should('be.visible') which retries until the button is visible before clicking.
  3. Final Answer:

    cy.get('.btn').should('be.visible').click() -> Option D
  4. Quick Check:

    Use get + should for retry-ability [OK]
Hint: Use get() with should() for retry-ability in Cypress [OK]
Common Mistakes:
  • Using cy.click() directly without get()
  • Relying on fixed wait times instead of should()
  • Missing should() causes no retry
3. Consider this Cypress code snippet:
cy.get('#status').should('contain', 'Success')
cy.get('#submit').click()

What happens if the element with id status initially does not contain 'Success' but updates after 2 seconds?
medium
A. The test fails immediately because 'Success' is not found
B. The test skips the assertion and clicks submit immediately
C. Cypress retries the assertion until 'Success' appears or timeout
D. The test waits 2 seconds automatically before clicking submit

Solution

  1. Step 1: Understand retry-ability with should()

    The should('contain', 'Success') assertion retries until the text appears or timeout.
  2. Step 2: Analyze behavior when text updates after 2 seconds

    Cypress waits and retries the assertion, so it passes once 'Success' appears, then proceeds to click.
  3. Final Answer:

    Cypress retries the assertion until 'Success' appears or timeout -> Option C
  4. Quick Check:

    should() retries until condition met [OK]
Hint: should() retries assertions until success or timeout [OK]
Common Mistakes:
  • Assuming test fails immediately without retry
  • Thinking Cypress waits fixed time automatically
  • Believing test skips assertion
4. You wrote this Cypress test:
cy.get('.loading').should('not.exist')
cy.get('.content').click()

But the test fails because .content is not clickable yet. What is the likely cause?
medium
A. The get('.content') command does not wait for element to be clickable
B. The should('not.exist') does not retry properly for .loading
C. You need to add wait() before clicking .content
D. The selector .content is incorrect

Solution

  1. Step 1: Understand retry-ability of should('not.exist')

    The should('not.exist') retries until the loading element disappears, so this part works correctly.
  2. Step 2: Analyze get('.content').click() behavior

    The get command retries until the element exists but does not wait for it to be clickable or visible before clicking.
  3. Final Answer:

    The get('.content') command does not wait for element to be clickable -> Option A
  4. Quick Check:

    get() waits for existence, not clickability [OK]
Hint: get() waits for element existence, not clickability [OK]
Common Mistakes:
  • Assuming should('not.exist') fails to retry
  • Adding unnecessary fixed waits
  • Blaming wrong selector without checking
5. You want to test a button that appears only after a loading spinner disappears. Which Cypress command sequence best uses retry-ability to ensure the button is clicked only when ready?
hard
A. cy.get('.spinner').should('not.exist') cy.get('button#submit').click()
B. cy.get('.spinner').should('not.exist') cy.get('button#submit').should('be.visible').click()
C. cy.get('button#submit').should('be.visible').click()
D. cy.wait(3000) cy.get('button#submit').click()

Solution

  1. Step 1: Wait for spinner to disappear

    Using should('not.exist') on spinner retries until spinner is gone, ensuring loading finished.
  2. Step 2: Wait for button to be visible before clicking

    Using should('be.visible') retries until button is visible and ready for click, avoiding flaky clicks.
  3. Final Answer:

    cy.get('.spinner').should('not.exist') cy.get('button#submit').should('be.visible').click() -> Option B
  4. Quick Check:

    Chain should() assertions for reliable waits [OK]
Hint: Chain should('not.exist') and should('be.visible') for reliable clicks [OK]
Common Mistakes:
  • Clicking button immediately after spinner disappears without visibility check
  • Using fixed wait instead of retry-ability
  • Skipping spinner wait and causing flaky tests
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