| title | go |
|---|
Navigate back or forward to the previous or next URL in the browser's history.
cy.go(direction)
cy.go(direction, options){% fa fa-check-circle green %} Correct Usage
cy.go('back'){% fa fa-angle-right %} direction (String, Number)
The direction to navigate.
You can use back or forward to go one step back or forward. You could also navigate to a specific history position (-1 goes back one page, 1 goes forward one page, etc).
{% fa fa-angle-right %} options (Object)
Pass in an options object to change the default behavior of cy.go().
| Option | Default | Description |
|---|---|---|
log |
true |
{% usage_options log %} |
timeout |
{% url pageLoadTimeout configuration#Timeouts %} |
{% usage_options timeout cy.go %} |
{% yields sets_subject cy.go 'yields the window object after the page finishes loading' %}
cy.go('back') // equivalent to clicking back buttoncy.go('forward') // equivalent to clicking forward buttoncy.go(-1) // equivalent to clicking back buttoncy.go(1) // equivalent to clicking forward buttonIf going forward or back causes a full page refresh, Cypress will wait for the new page to load before moving on to new commands.
Cypress additionally handles situations where a page load was not caused (such as hash routing) and will resolve immediately.
{% requirements page cy.go %}
{% assertions wait cy.go %}
{% timeouts page cy.go %}
Go back in browser's history
cy
.visit('http://localhost:8000/folders')
.go('back')The commands above will display in the Command Log as:
{% imgTag /img/api/go/test-showing-go-back-browser-button.png "Command Log go" %}
When clicking on the go command within the command log, the console outputs the following:
{% imgTag /img/api/go/window-is-logged-when-go-back-in-browser-history.png "console Log go" %}
- {% url
cy.reload()reload %} - {% url
cy.visit()visit %}