0
0
Cypresstesting~10 mins

Negative assertions (not) in Cypress - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test checks that a specific button is not visible on the page. It verifies that the negative assertion using not works correctly in Cypress.

Test Code - Cypress
Cypress
describe('Negative assertion test', () => {
  it('checks that the submit button is not visible', () => {
    cy.visit('https://example.com/login')
    cy.get('#submit-btn').should('not.be.visible')
  })
})
Execution Trace - 4 Steps
StepActionSystem StateAssertionResult
1Test startsTest runner initialized, ready to execute test-PASS
2Browser opens and navigates to 'https://example.com/login'Login page is loaded in the browser-PASS
3Find element with id 'submit-btn' using cy.get('#submit-btn')Element '#submit-btn' is located in the DOM-PASS
4Check that '#submit-btn' is not visible using .should('not.be.visible')Element '#submit-btn' is present but hidden or not displayedVerify '#submit-btn' is not visible on the pagePASS
Failure Scenario
Failing Condition: The '#submit-btn' element is visible on the page when the test expects it to be hidden
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test verify about the '#submit-btn' element?
AThat the button is not visible on the page
BThat the button is visible on the page
CThat the button is enabled
DThat the button has the correct text
Key Result
Using negative assertions like 'not.be.visible' helps confirm that unwanted elements are hidden, improving test accuracy and user experience validation.