# Cypress Custom Commands

> For the complete documentation index, see [llms.txt](https://www.jetbrains.com/help/go/2026.3/llms.txt).

[Custom Commands](https://docs.cypress.io/api/cypress-api/custom-commands) provide a way to reuse certain methods or functions across the Cypress test suite. For example, you can write a command to log in the user and reuse it within your project whenever applicable.

GoLand supports Custom Commands, meaning that all coding assistance features, such as renaming, navigation, code completion, and inspections are available right away.

## Custom Commands coding assistance

### Cypress-specific inspections

Cypress utilizes a [chaining mechanism](https://docs.cypress.io/guides/core-concepts/introduction-to-cypress#Chains-of-Commands) that allows you to write a sequence of commands where information is passed from one command to the next until the chain ends or an error occurs.

After an action command such as `click()`, the element passed to the next command can become outdated. GoLand warns about unsafe command chains. Start a new chain to find the element again.

Incorrect usage:

This chain passes the clicked button to `type()` instead of finding the input field.

```JAVASCRIPT
it('Click the search button and type Cypress', () => {
    cy.get("button[data-test='search-button']")
        .click()
        .type('Cypress')
 })
```

Correct usage:

Start a new chain to find the input field after clicking the button:

```JAVASCRIPT
it('Click the search button and type Cypress', () => {
    cy.get("button[data-test='search-button']").click()
    cy.get("input[data-test$='inner']").type('Cypress')
})
```

The command-chain inspection also warns when a command receives an incompatible element or value.

![Inspection for an incorrect chained command](https://resources.jetbrains.com/help/img/idea/2026.3/aqua_incorrect_command_chain.png)

### Function-specific inspections

GoLand performs function-specific code inspections that detect and correct abnormal code in your project.

For example, if you provide an incorrect number or type of arguments for the command, the erroneous code gets highlighted. You can hover the mouse over the highlighted code to see the description of the error.

![Aqua ts function specific inspections](https://resources.jetbrains.com/help/img/idea/2026.3/aqua_ts_function_specific_inspections.png)

For more information, refer to [Code inspections](code-inspection.html).

### Renaming

If you need to rename the command, you can use the Rename refactoring. To do this:

Procedure:

1. Highlight the command that you want to rename.

![Highlighted command](https://resources.jetbrains.com/help/img/idea/2026.3/aqua_highlighted_command.png)

2. Press `Shift+F6` (Windows), `⇧ F6` (macOS), `⇧ F6` (IntelliJ IDEA Classic (macOS)), `⌘ ⌥ R` (macOS System Shortcuts), `Shift+F6` (XWin), `Shift+F6` (GNOME), `Shift+F6` (KDE), `Shift+F6` (Emacs), `Shift+F6` (Sublime Text), `⇧ F6` (Sublime Text (macOS)), `F2` (VSCode), `F2` (VSCode (macOS)) and provide a new name for the command.

![Rename the command](https://resources.jetbrains.com/help/img/idea/2026.3/aqua_rename_refactoring.png)

3. (Optional) Configure additional search options and define scope.

4. Click Refactor.

For more information, refer to [Rename refactorings](rename-refactorings.html).

## Creating a Custom Command

To create a Custom Command, you have to first write the command, and then create a TypeScript declaration for it. To do this:

Procedure:

1. Write your command in the code editor.

> **Note:**
> It is recommended to specify commands in the `cypress/support/commands.ts` or `cypress/support/commands.js` file, since this file is loaded via an import statement provided in the [supportFile](https://docs.cypress.io/guides/core-concepts/writing-and-organizing-tests#Support-file) before any test files are evaluated.

TypeScript:

![Custom Command written in TypeScript](https://resources.jetbrains.com/help/img/idea/2026.3/aqua_ts_cypress_command.png)

JavaScript:

![Custom Command written in TypeScript](https://resources.jetbrains.com/help/img/idea/2026.3/aqua_js_cypress_command.png)

> **Tip:**
> Initially, GoLand highlights the command as an error or weak warning, depending on the programming language selected for the project. However, once you create a TypeScript declaration, the issue will be resolved.

2. Hover the mouse over the highlighted code and click Create missing TypeScript declaration.

Alternatively, place the caret at the highlighted code, press `Alt+Enter` (Windows), `⌥ ⏎` (macOS), `⌥ ⏎` (IntelliJ IDEA Classic (macOS)), `⌥ ⏎` (macOS System Shortcuts), `Alt+Enter` (XWin), `Alt+Enter` (GNOME), `Alt+Enter` (KDE), `Alt+Enter` (Emacs), `Alt+Enter` (Sublime Text), `⌥ ⏎` (Sublime Text (macOS)), `Ctrl+.` (VSCode), `⌘ .` (VSCode (macOS)), and select Create missing TypeScript declaration.

TypeScript:

![Creating the TypeScript declaration](https://resources.jetbrains.com/help/img/idea/2026.3/aqua_creating_ts_declaration.png)

JavaScript:

![Creating the JavaScript declaration](https://resources.jetbrains.com/help/img/idea/2026.3/index.d.ts` file.

![Generated TypeScript declaration](https://resources.jetbrains.com/help/img/idea/2026.3/aqua_generated_ts_declaration.png)

> **Tip:**
> If needed, you can [change the location](#change_location_of_command_file) of the `index.d.ts` file in settings.

## Navigating to a TypeScript declaration

You might want to navigate between the command implementation and the corresponding TypeScript declaration:

Procedure:

* To navigate to the TypeScript declaration, click ![](https://resources.jetbrains.com/help/img/idea/2026.3/app-client.expui.gutter.implementingMethod.svg) in the gutter near the command implementation.

![Navigate to TypeScript declaration](https://resources.jetbrains.com/help/img/idea/2026.3/aqua_go_to_ts_declaration.png)

* To navigate back to the command implementation, click ![](https://resources.jetbrains.com/help/img/idea/2026.3/app-client.expui.gutter.implementedMethod.svg) in the gutter near the TypeScript declaration.

![Navigate to command implementation](https://resources.jetbrains.com/help/img/idea/2026.3/aqua_go_to_command_declaration.png)

## Using Custom Commands

Once you have [created](#creating_custom_commands) a custom command, you can use it in your code. To do this:

Procedure:

* In your test, type `cy.` followed by the name of the custom command.

Custom Command:

![Custom login command](https://resources.jetbrains.com/help/img/idea/2026.3/aqua_custom_login_command.png)

Usage:

![Custom login command usage](https://resources.jetbrains.com/help/img/idea/2026.3/index.d.ts`. If you want to change the location:

Procedure:

1. Press `Ctrl+Alt+S` (Windows), `⌘ Comma` (macOS), `⌘ Comma` (IntelliJ IDEA Classic (macOS)), `⌘ Comma` (macOS System Shortcuts), `Ctrl+Alt+S` (XWin), `Ctrl+Alt+S` (GNOME), `Ctrl+Alt+S` (KDE), `Ctrl+Alt+S` (Emacs), `Ctrl+Alt+S` (Sublime Text), `⌘ Comma` (Sublime Text (macOS)), `Ctrl+Comma` (VSCode), `⌘ Comma` (VSCode (macOS)) to open settings and then select `Languages & Frameworks | Cypress`.

2. In the TypeScript file to store TS declarations of custom commands field, specify a new path.

![Specify a new path](https://resources.jetbrains.com/help/img/idea/2026.3/go_custom_commands_settings.png)

3. Apply the changes and close the dialog.

## See also

### External Links

[Cypress Custom Commands](https://docs.cypress.io/api/cypress-api/custom-commands) [Cypress chaining mechanism](https://docs.cypress.io/guides/core-concepts/introduction-to-cypress#Chains-of-Commands) [Cypress action commands](https://docs.cypress.io/guides/core-concepts/interacting-with-elements#Actionability)

