Challenge - 5 Problems
Negative Assertions Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the test result of this Cypress code?
Consider this Cypress test code snippet:
What will be the test result if the button is enabled?
cy.get('#submit-button').should('not.be.disabled')What will be the test result if the button is enabled?
Cypress
cy.get('#submit-button').should('not.be.disabled')
Attempts:
2 left
💡 Hint
Think about what 'not.be.disabled' means for an enabled button.
✗ Incorrect
The assertion 'not.be.disabled' checks that the element is not disabled. If the button is enabled, it is not disabled, so the test passes.
❓ assertion
intermediate2:00remaining
Which assertion correctly verifies an element is NOT visible?
You want to check that an element with class '.popup' is not visible on the page. Which Cypress assertion is correct?
Attempts:
2 left
💡 Hint
Focus on the correct Cypress assertion syntax for visibility.
✗ Incorrect
The correct way to assert an element is not visible is 'should('not.be.visible')'. 'be.hidden' and 'be.invisible' are not valid Cypress assertions. 'not.exist' checks if the element is absent, not just invisible.
🔧 Debug
advanced2:00remaining
Why does this negative assertion fail unexpectedly?
Given the code:
The test fails even though the element does not have the 'active' class. What is the likely cause?
cy.get('#login').should('not.have.class', 'active')The test fails even though the element does not have the 'active' class. What is the likely cause?
Cypress
cy.get('#login').should('not.have.class', 'active')
Attempts:
2 left
💡 Hint
Consider if the element's class changes after the assertion runs.
✗ Incorrect
The test fails because the element still has the 'active' class when the assertion runs. This is often due to timing issues where the class is removed later. Cypress retries assertions, but if the class is present initially, the test fails.
❓ locator
advanced2:00remaining
Which locator is best for a negative assertion on a disabled button?
You want to assert that a button with text 'Submit' is NOT disabled. Which locator and assertion combination is best?
Attempts:
2 left
💡 Hint
Think about combining text locator with a negative assertion on disabled state.
✗ Incorrect
Option A uses cy.contains to find the button by text and asserts it is not disabled, which is clear and reliable. Option A tries to find disabled buttons with text and assert non-existence, which is indirect. Option A is valid but less direct than A. Option A uses an invalid attribute selector.
❓ framework
expert2:00remaining
How does Cypress handle negative assertions internally?
Which statement best describes how Cypress processes negative assertions like
should('not.exist') or should('not.be.visible')?Attempts:
2 left
💡 Hint
Think about Cypress's retry-ability feature and how it applies to negative assertions.
✗ Incorrect
Cypress automatically retries assertions, including negative ones, until they pass or timeout. This means it waits for the element to disappear or become invisible before passing the test.