0
0
Cypresstesting~20 mins

Multiple assertions chaining in Cypress - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Multiple Assertions Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
assertion
intermediate
2:00remaining
Chaining multiple assertions on a button element
Given the Cypress test code below, what will be the result of running it if the button has text 'Submit' and is visible and enabled?
Cypress
cy.get('button#submit-btn').should('be.visible').and('contain.text', 'Submit').and('be.enabled')
ATest passes because all assertions are true
BTest fails because 'contain.text' is not a valid assertion
CTest fails because chaining multiple 'and' is not allowed
DTest fails because 'be.enabled' is not a valid assertion
Attempts:
2 left
💡 Hint
Remember that Cypress allows chaining multiple assertions with 'and' if they apply to the same subject.
assertion
intermediate
2:00remaining
Understanding failure in chained assertions
What happens when the following Cypress test runs if the element with id 'login' is visible but does NOT contain the text 'Welcome'?
Cypress
cy.get('#login').should('be.visible').and('contain.text', 'Welcome')
ATest fails at the second assertion with a clear error message
BTest passes because the first assertion is true
CTest fails at the first assertion due to visibility check
DTest passes but logs a warning about missing text
Attempts:
2 left
💡 Hint
Chained assertions stop at the first failure and report it.
Predict Output
advanced
2:00remaining
Output of chained assertions with negation
What is the test result when running this Cypress code if the input field with id 'email' is visible and empty?
Cypress
cy.get('#email').should('be.visible').and('have.value', '').and('not.be.disabled')
ATest fails because the input is empty and should have a value
BTest fails because 'have.value' cannot check empty string
CTest fails because 'not.be.disabled' is invalid syntax
DTest passes because all assertions are true
Attempts:
2 left
💡 Hint
Check carefully each assertion and what it expects.
🔧 Debug
advanced
2:00remaining
Identify the error in chained assertions
What error will Cypress report when running this code snippet?
Cypress
cy.get('.nav-link').should('be.visible').and('have.text')
ASyntaxError due to missing parentheses
BTest fails because 'have.text' is not a valid assertion
CTypeError because 'have.text' requires an argument
DTest passes because 'have.text' checks for any text
Attempts:
2 left
💡 Hint
Check the usage of 'have.text' assertion in Cypress documentation.
framework
expert
3:00remaining
Best practice for chaining multiple assertions on different elements
Which Cypress code snippet correctly chains assertions on two different elements without causing errors?
Acy.get('#header').should('be.visible').and('contain.text', 'Welcome').and(cy.get('#footer').should('be.visible'))
Bcy.get('#header').should('be.visible').and('contain.text', 'Welcome').then(() => cy.get('#footer').should('be.visible'))
Ccy.get('#header').should('be.visible').and('contain.text', 'Welcome'); cy.get('#footer').should('be.visible')
Dcy.get('#header').should('be.visible').and('contain.text', 'Welcome').get('#footer').should('be.visible')
Attempts:
2 left
💡 Hint
Remember that chaining 'and' continues assertions on the same subject only.