Cypress go Command

Profile picture for user arilio666

If we want to navigate back and forward to the previous or the next URL in browser history, then the Cypress go command is the one to use.

It yields the window object after the page finishes loading. If going forward or back causes a full page refresh, Cypress will wait for the new page to load before executing the next commands.

Go Command Syntax

cy.go(direction, options)


  1. direction(string, number):
    • We can use back and forward to travel back and forth the page, and
    • Also, we can use -1 and 1 to travel back and forth to a specific history position.
  2. Options:
    • Log: To display the command in the command log.
    • Timeout: Wait for cy.go(), to get finished before timing out.

Correct Use:

 //same as browser forward button

//same as browser back button

Rules And Requirements

  • It must be chained off with cy.
  • The response should be of content-type: text/html.
  • Require load event to fire.
  • Require the response code to be 2xx after following redirect

Example Cypress Go

Let us do some practical real-time examples of the go command.

Here is the scenario:

  1. Visit the site
  2. Click on ask a doubt.
  3. Click on the login.
  4. Navigate back and forth using the go command directions.
describe('Go Command',()=>{
    before(() => {
        it('Navigate Back And Forth Using GO Command',()=>{
            cy.contains('Ask Doubt').click()

Cypress go Command

We can see from the command log that it has successfully navigated between pages with ease.