Test Overview
This test verifies that the page reloads correctly using cy.reload() and that a specific element is visible after the reload.
This test verifies that the page reloads correctly using cy.reload() and that a specific element is visible after the reload.
describe('Page reload test', () => { it('Reloads the page and checks element visibility', () => { cy.visit('https://example.cypress.io') cy.get('h1').should('be.visible') cy.reload() cy.get('h1').should('be.visible') }) })
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts | Test runner initialized, no browser actions yet | — | PASS |
| 2 | Browser opens and navigates to 'https://example.cypress.io' | Page loads with visible <h1> element | — | PASS |
| 3 | Finds <h1> element | <h1> element is present and visible on the page | Check that <h1> is visible | PASS |
| 4 | Calls cy.reload() to reload the page | Page reloads, content refreshes | — | PASS |
| 5 | Finds <h1> element again after reload | <h1> element is present and visible after reload | Check that <h1> is visible after reload | PASS |
cy.reload() in Cypress testing?cy.reload()cy.reload() is used to refresh the current page in a Cypress test, simulating a browser refresh.cy.reload()true forces reload without cache.cy.reload(true) correctly uses the boolean parameter. Options C and D use incorrect syntax, and B reloads with cache.cy.visit('/home')
cy.get('#refresh-btn').click()
cy.reload()
cy.get('.welcome-message').should('be.visible')cy.reload() is called?cy.reload().cy.reload(cache: true)
cy.reload()cache: true inside parentheses is invalid syntax in JavaScript function calls.cy.reload(true) to force reload without cache, which can clear cookies.getCookie('session_id').should('not.exist') to assert the cookie is cleared.Pass the test and this pattern moves unknown