# Cypress Custom Commands

> **Note:**
> Cypress Custom Commands support in IntelliJ IDEA is provided by the [Test Automation](https://plugins.jetbrains.com/plugin/20175-test-automation) plugin. If the relevant features are not available, make sure that the plugin is [installed and enabled](ui-test-automation.html#install_test_automation_plugin).

[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.

IntelliJ IDEA 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.

However, this mechanism has some specifics. For example, any [action command](https://docs.cypress.io/guides/core-concepts/interacting-with-elements#Actionability) must always be placed at the end of the chain and used only once.

Incorrect usage:

In this example, the chain contains two action commands placed one after another, which is prohibited. The execution of this test will result in an error.

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

Correct usage:

In this example, the chain is split in two, so each chain contains only one action command. This test will be executed without an issue.

```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')
})
```

Validation of the command chain is not performed in JavaScript/TypeScript, and in Cypress it is performed only at runtime, which may lead to issues during the test execution. IntelliJ IDEA, in its turn, provides an inspection for chained commands, highlighting incorrect usages.

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

### Function-specific inspections

IntelliJ IDEA 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.cn/help/img/idea/2026.2/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.cn/help/img/idea/2026.2/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)), `Ctrl+R` (NetBeans), `Ctrl+R, R` (Visual Studio), `⌘ R, R` (Visual Studio (macOS)), `Alt+Shift+R` (Eclipse), `⇧ F6` (Eclipse (macOS)) and provide a new name for the command.

![Rename the command](https://resources.jetbrains.com.cn/help/img/idea/2026.2/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.cn/help/img/idea/2026.2/aqua_ts_cypress_command.png)

JavaScript:

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

> **Tip:**
> Initially, IntelliJ IDEA 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)), `Alt+Enter` (NetBeans), `Alt+Enter` (Visual Studio), `⌥ ⏎` (Visual Studio (macOS)), `Ctrl+1` (Eclipse), `⌘ 1` (Eclipse (macOS)), and select Create missing TypeScript declaration.

TypeScript:

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

JavaScript:

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

![Generated TypeScript declaration](https://resources.jetbrains.com.cn/help/img/idea/2026.2/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.cn/help/img/idea/2026.2/app-client.expui.gutter.implementingMethod.svg) in the gutter near the command implementation.

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

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

![Navigate to command implementation](https://resources.jetbrains.com.cn/help/img/idea/2026.2/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.cn/help/img/idea/2026.2/aqua_custom_login_command.png)

Usage:

![Custom login command usage](https://resources.jetbrains.com.cn/help/img/idea/2026.2/commands.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+Alt+S` (NetBeans), `Ctrl+Alt+S` (Visual Studio), `⌘ Comma` (Visual Studio (macOS)), `Ctrl+Alt+S` (Eclipse), `⌘ Comma` (Eclipse (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.cn/help/img/idea/2026.2/aqua_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)

