0
0
Cypresstesting~20 mins

Negative assertions (not) in Cypress - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Negative Assertions Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the test result of this Cypress code?
Consider this Cypress test code snippet:
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')
AThe test is skipped because 'not' is not a valid assertion.
BThe test fails because the button is enabled.
CThe test throws a syntax error due to incorrect assertion.
DThe test passes because the button is enabled (not disabled).
Attempts:
2 left
💡 Hint
Think about what 'not.be.disabled' means for an enabled button.
assertion
intermediate
2: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?
Acy.get('.popup').should('not.exist')
Bcy.get('.popup').should('be.hidden')
Ccy.get('.popup').should('not.be.visible')
Dcy.get('.popup').should('be.invisible')
Attempts:
2 left
💡 Hint
Focus on the correct Cypress assertion syntax for visibility.
🔧 Debug
advanced
2:00remaining
Why does this negative assertion fail unexpectedly?
Given the code:
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')
AThe assertion is correct; the test fails due to a timing issue before the class is removed.
BThe element is detached from the DOM when the assertion runs, causing failure.
CThe element has multiple classes including 'active', so the assertion fails.
DThe 'not' keyword is not supported with 'have.class' in Cypress.
Attempts:
2 left
💡 Hint
Consider if the element's class changes after the assertion runs.
locator
advanced
2: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?
Acy.contains('button', 'Submit').should('not.be.disabled')
Bcy.get('button:disabled').contains('Submit').should('not.exist')
Ccy.get('button').contains('Submit').should('not.have.attr', 'disabled')
Dcy.get('button[disabled=false]').contains('Submit')
Attempts:
2 left
💡 Hint
Think about combining text locator with a negative assertion on disabled state.
framework
expert
2: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')?
ACypress converts negative assertions into positive ones by inverting the condition before checking once.
BCypress retries the assertion until the element disappears or becomes invisible within the default timeout.
CCypress immediately fails the test if the element exists or is visible at the first check.
DCypress disables retries for negative assertions to avoid false positives.
Attempts:
2 left
💡 Hint
Think about Cypress's retry-ability feature and how it applies to negative assertions.