We use cy.reload() to refresh the current web page during a test. This helps check if the page loads correctly again or if changes persist after reloading.
0
0
cy.reload() in Cypress
Introduction
You want to test if a form submission keeps data after refreshing.
You need to verify that a page shows updated content after reload.
You want to simulate a user pressing the browser refresh button.
You want to clear temporary page states by reloading.
You want to test if error messages disappear after a reload.
Syntax
Cypress
cy.reload(options?)
The options parameter is optional and can control how the reload happens.
By default, cy.reload() reloads the page without forcing the browser to fetch from the server cache.
Examples
Reloads the current page normally.
Cypress
cy.reload()
Reloads the page and forces the browser to fetch fresh content from the server, ignoring cache.
Cypress
cy.reload(true)Reloads the page and waits up to 10 seconds for the reload to complete.
Cypress
cy.reload({ timeout: 10000 })Sample Program
This test visits a page, checks the title, reloads the page, and checks the title again to confirm the reload worked.
Cypress
describe('Reload page test', () => { it('should reload the page and keep the title', () => { cy.visit('https://example.cypress.io') cy.title().should('include', 'Kitchen Sink') cy.reload() cy.title().should('include', 'Kitchen Sink') }) })
OutputSuccess
Important Notes
Reloading can help test if your app handles page refreshes gracefully.
Use cy.reload(true) to force a full reload from the server, useful when testing cache issues.
Reloading resets the page state, so any temporary data in memory will be lost.
Summary
cy.reload() refreshes the current page during a test.
It helps verify page behavior after a user refreshes the browser.
You can control reload behavior with optional parameters.