What if you could control browser back and forward buttons with just one command in your tests?
Why cy.go() for browser history in Cypress? - Purpose & Use Cases
Imagine testing a website where you need to check if clicking links changes pages correctly. You try to go back and forth in the browser history manually, clicking the back and forward buttons each time.
Doing this by hand is slow and boring. You might forget to click the right button or miss a step. It's easy to make mistakes and hard to repeat the exact same steps every time.
Using cy.go() in Cypress lets you control browser history with simple commands. You can move back or forward in history automatically, making tests faster, reliable, and repeatable.
Visit page A Click link to page B Click browser back button Check page A loads
cy.visit('pageA') cy.get('a[href="pageB"]').click() cy.go('back') cy.url().should('include', 'pageA')
It enables automated, precise control of browser navigation to test user flows without manual clicks.
Testing an online store where users browse products, then go back to the list to choose another item. cy.go() helps simulate this navigation smoothly in tests.
Manual browser navigation in tests is slow and error-prone.
cy.go() automates moving through browser history easily.
This makes tests faster, reliable, and repeatable.