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.
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.
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') }) })
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts | Test runner initialized, ready to execute test | — | PASS |
| 2 | Browser opens and navigates to 'https://example.com/login' | Login page is loaded in the browser | — | PASS |
| 3 | Find element with id 'submit-btn' using cy.get('#submit-btn') | Element '#submit-btn' is located in the DOM | — | PASS |
| 4 | Check that '#submit-btn' is not visible using .should('not.be.visible') | Element '#submit-btn' is present but hidden or not displayed | Verify '#submit-btn' is not visible on the page | PASS |
cy.get('button').should('not.exist') check for?should('not.exist')buttoncy.get('button').should('not.exist') verifies that no button element is present in the page.#modal is hidden?should('not.be.visible').be.hidden. cy.get('#modal').should('not.visible') has incorrect syntax not.visible.cy.get('.alert').should('not.exist')
cy.get('.alert').should('not.be.visible').alert is present but hidden?should('not.exist') when element is present but hiddenshould('not.be.visible') when element is hiddency.get('.popup').should('not.exist')div with class .notification is neither present nor visible on the page. Which Cypress code correctly checks both conditions?should('not.exist') alone is enough to confirm element is absent and thus not visible.Pass the test and this pattern moves unknown