mirror of
https://github.com/cypress-io/cypress.git
synced 2026-05-24 17:38:52 -05:00
93 lines
2.8 KiB
Markdown
93 lines
2.8 KiB
Markdown
---
|
|
title: go
|
|
comments: true
|
|
description: ''
|
|
---
|
|
|
|
Navigate back or forward to the previous or next URL in the browser's history. If 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.
|
|
|
|
| | |
|
|
|--- | --- |
|
|
| **Returns** | the `window` object |
|
|
| **Timeout** | `cy.go` will retry for the duration of the [pageLoadTimeout](https://on.cypress.io/guides/configuration#timeouts) or the duration of the `timeout` specified in the command's [options](#options). |
|
|
|
|
# [cy.go( *direction* )](#direction-usage)
|
|
|
|
Navigate back or forward to the URL in a specific direction (`back` or `forward`).
|
|
|
|
# [cy.go( *number* )](#number-usage)
|
|
|
|
Navigate back or forward going to the URL within a specific history position (-1 goes back one page, 1 goes forward one page).
|
|
|
|
# Options
|
|
|
|
Pass in an options object to change the default behavior of `cy.go`.
|
|
|
|
**cy.go( *direction*, *options* )**
|
|
**cy.go( *number*, *options* )**
|
|
|
|
Option | Default | Notes
|
|
--- | --- | ---
|
|
`timeout` | [pageLoadTimeout](https://on.cypress.io/guides/configuration#timeouts) | Total time to retry the visit
|
|
`log` | `true` | whether to display command in command log
|
|
|
|
# Direction Usage
|
|
|
|
## Go back in browser's history
|
|
|
|
```javascript
|
|
cy.go("back") // equivalent to clicking back button
|
|
```
|
|
|
|
## Go forward in browser's history
|
|
|
|
```javascript
|
|
cy.go("forward") // equivalent to clicking forward button
|
|
```
|
|
|
|
# Number Usage
|
|
|
|
## Go back in browser's history
|
|
|
|
```javascript
|
|
cy.go(-1) // equivalent to clicking back button
|
|
```
|
|
|
|
## Go forward in browser's history
|
|
|
|
```javascript
|
|
cy.go(1) // equivalent to clicking forward button
|
|
```
|
|
|
|
# Command Log
|
|
|
|
## Go back in browser's history
|
|
|
|
```javascript
|
|
cy
|
|
.visit("http://localhost:8000/folders")
|
|
.go("back")
|
|
```
|
|
|
|
The commands above will display in the command log as:
|
|
|
|

|
|
|
|
When clicking on the `get` command within the command log, the console outputs the following:
|
|
|
|

|
|
|
|
# Errors
|
|
|
|
## cy.go() accepts only a string or number argument
|
|
|
|
`cy.go()` specifically accepts the string arguments `back` or `forward` or a number argument to navigate to a specific position in the history.
|
|
|
|
## cy.go() cannot accept '0'. The number must be greater or less than '0'.
|
|
|
|
Ensure the number passed to `cy.go()` navigates forward or backward in history. For example, -1 goes back one page, 1 goes forward one page.
|
|
|
|
# Related
|
|
|
|
- [visit](https://on.cypress.io/api/visit)
|