Consider the following Cypress code snippet:
cy.get('button.submit').should('be.visible').and('contain.text', 'Send')What happens if the button is visible but its text is 'Submit' instead of 'Send'?
cy.get('button.submit').should('be.visible').and('contain.text', 'Send')
Remember that should() with and() chains all assertions and all must pass.
The should('be.visible') passes, but and('contain.text', 'Send') fails because the button text is 'Submit'. Both must pass for the test to pass.
You want to verify that an input field is disabled and has the placeholder text 'Enter name'. Which of the following chained should() assertions is correct?
Each should() or and() takes one assertion at a time.
Option C chains two separate assertions correctly. Option C also works but the question asks for the correct chained assertion starting with be.disabled. Option C and D misuse the should() syntax by combining multiple assertions in one call.
Examine this Cypress code:
cy.get('div.alert').should('have.class', 'error').and('contain', 123)It fails with a TypeError. Why?
Check the expected argument types for contain.
The contain chainer expects a string or RegExp. Passing a number like 123 causes a TypeError during assertion.
should() calls in Cypress?Consider this code:
cy.get('input').should('be.visible').should('be.enabled')How does Cypress handle these chained should() calls?
Think about how Cypress chains commands and assertions.
Each should() is a separate assertion. Cypress runs them sequentially and both must pass for the test to pass.
should() assertion correctly verifies a list with exactly 3 visible items containing 'Item' text?You want to check that a list has exactly 3 visible li elements and each contains the text 'Item'. Which chained assertion is correct?
Remember that each() is a separate command, not a chainer for should().
Option A correctly chains should() assertions and then uses each() to check each element's text. Option A incorrectly chains contain.text on the whole set. Option A tries to chain each inside and() which is invalid. Option A misuses and() with a callback.