0
0
Cypresstesting~20 mins

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

Choose your learning style9 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.