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?
cy.get('button.submit').click()
Think about how Cypress handles commands that query elements.
Cypress automatically retries get commands until the element appears or the default timeout expires. Only then it performs the click. This retry-ability helps tests be more stable.
Given this code snippet:
cy.get('.message').should('contain', 'Success')Which statement about the assertion is true?
cy.get('.message').should('contain', 'Success')
Remember how Cypress handles chained commands and assertions.
Cypress retries both the element query and the assertion until the condition is met or timeout. This makes tests more reliable when UI updates take time.
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?
cy.get('#loadButton').click() cy.get('#result').should('have.text', 'Loaded')
Think about what Cypress retries and what it does not.
Cypress retries queries and assertions but does not retry actions like click(). If the click triggers loading asynchronously, the assertion may run before the UI updates. Adding waits or chaining properly can fix this.
Choose the command that Cypress does NOT retry automatically when it fails.
Consider which commands are queries/assertions and which are actions.
Cypress retries queries like get, contains, and assertions like should. It does not retry actions like click or type. Actions run once when called.
You want to increase the time Cypress retries a get command before failing. Which option correctly sets a custom timeout for just that command?
Check Cypress docs for command options syntax.
Cypress commands accept an options object as the second argument where you can specify timeout in milliseconds. This overrides the default retry timeout for that command only.