0
0
Cypresstesting~20 mins

should() with chainers in Cypress - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Cypress Should() Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the result of this Cypress test assertion?

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'?

Cypress
cy.get('button.submit').should('be.visible').and('contain.text', 'Send')
AThe test ignores the text check and passes.
BThe test passes because the button is visible.
CThe test throws a syntax error due to chaining.
DThe test fails because the text does not contain 'Send'.
Attempts:
2 left
💡 Hint

Remember that should() with and() chains all assertions and all must pass.

assertion
intermediate
2:00remaining
Which chained assertion correctly checks for a disabled input with a specific placeholder?

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?

Acy.get('input#name').should('have.attr', 'placeholder', 'Enter name').and('be.disabled')
Bcy.get('input#name').should('be.disabled', 'have.attr', 'placeholder', 'Enter name')
Ccy.get('input#name').should('be.disabled').and('have.attr', 'placeholder', 'Enter name')
Dcy.get('input#name').should('have.attr', 'placeholder').and('be.disabled', 'Enter name')
Attempts:
2 left
💡 Hint

Each should() or and() takes one assertion at a time.

🔧 Debug
advanced
2:00remaining
Why does this chained assertion fail with a TypeError?

Examine this Cypress code:

cy.get('div.alert').should('have.class', 'error').and('contain', 123)

It fails with a TypeError. Why?

AThe <code>have.class</code> chainer cannot be chained with <code>contain</code>.
BThe <code>contain</code> chainer expects a string, but 123 is a number causing a TypeError.
CThe selector <code>div.alert</code> is invalid causing the error.
DThe <code>and</code> method is not supported in Cypress chaining.
Attempts:
2 left
💡 Hint

Check the expected argument types for contain.

🧠 Conceptual
advanced
2:00remaining
What is the behavior of multiple chained should() calls in Cypress?

Consider this code:

cy.get('input').should('be.visible').should('be.enabled')

How does Cypress handle these chained should() calls?

AEach <code>should()</code> is a separate assertion and both must pass independently.
BOnly the first <code>should()</code> runs; the second is ignored.
CThe second <code>should()</code> overrides the first one.
DCypress throws an error because multiple <code>should()</code> calls are not allowed.
Attempts:
2 left
💡 Hint

Think about how Cypress chains commands and assertions.

framework
expert
3:00remaining
Which chained 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?

Acy.get('ul#list > li').should('have.length', 3).and('be.visible').each(($el) => { expect($el).to.contain.text('Item') })
Bcy.get('ul#list > li').should('have.length', 3).and('each', ($el) => { expect($el).to.contain.text('Item') }).and('be.visible')
Ccy.get('ul#list > li').should('have.length', 3).and('be.visible').and(($els) => { expect($els).to.contain.text('Item') })
Dcy.get('ul#list > li').should('have.length', 3).and('be.visible').and('contain.text', 'Item')
Attempts:
2 left
💡 Hint

Remember that each() is a separate command, not a chainer for should().