Challenge - 5 Problems
Multiple Assertions Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ assertion
intermediate2: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')
Attempts:
2 left
💡 Hint
Remember that Cypress allows chaining multiple assertions with 'and' if they apply to the same subject.
✗ Incorrect
The code chains three assertions on the same button element: it checks visibility, text content, and enabled state. All are valid assertions and chaining with 'and' is supported, so the test passes if all conditions are met.
❓ assertion
intermediate2: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')
Attempts:
2 left
💡 Hint
Chained assertions stop at the first failure and report it.
✗ Incorrect
The first assertion 'be.visible' passes, but the second 'contain.text' fails because the text is missing. Cypress stops and reports the failure at the second assertion.
❓ Predict Output
advanced2: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')
Attempts:
2 left
💡 Hint
Check carefully each assertion and what it expects.
✗ Incorrect
The input is visible, has an empty value (''), and is not disabled. All assertions are valid and true, so the test passes.
🔧 Debug
advanced2: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')
Attempts:
2 left
💡 Hint
Check the usage of 'have.text' assertion in Cypress documentation.
✗ Incorrect
'have.text' requires a string argument to compare the element's text. Omitting it causes a TypeError during test execution.
❓ framework
expert3:00remaining
Best practice for chaining multiple assertions on different elements
Which Cypress code snippet correctly chains assertions on two different elements without causing errors?
Attempts:
2 left
💡 Hint
Remember that chaining 'and' continues assertions on the same subject only.
✗ Incorrect
Option B uses 'then' to run a new Cypress command for a different element after the first assertions complete, which is the correct way to chain assertions on different elements. Options B and D misuse chaining and cause errors. Option B runs commands sequentially but not chained.