← Back to library
Cypressnavigationbeginnerv10+

Browser back and forward navigation

Use cy.go() to navigate history and assert the URL at each step.

1it('back and forward navigation works', () => {
2  cy.visit('/page-a');
3  cy.get('a[href="/page-b"]').click();
4  cy.url().should('include', '/page-b');
5
6  cy.go('back');
7  cy.url().should('include', '/page-a');
8
9  cy.go('forward');
10  cy.url().should('include', '/page-b');
11});
#go back#go forward#history#url