Cypress Custom Commands
- Radek Stolarczyk
- 2 days ago
- 2 min read
This post explains how Cypress custom commands work, when they make sense, and when they should be avoided. It is written as a practical reference rather than a theoretical guide.

What Are Cypress Custom Commands?
Custom commands are global Cypress commands that can be called from any test or spec file.
Defined in cypress/support/commands.js
Available via cy.commandName() just like built-in commands
Basic syntax:

They are useful for removing duplication when the same operation is needed across the entire test suite.
IntelliSense Limitations and Workarounds
By default, VS Code IntelliSense does not recognize custom commands.
Common issues:
No autocomplete for custom commands
No direct navigation to the implementation
Commands must be manually searched in commands.js
Workaround:
Create an index.d.ts file in the support folder
Extend the Cypress namespace and Chainable interface
Declare custom commands with types
Add JSDoc comments for better documentation

This improves autocomplete and readability, but navigation still leads only to type definitions, not the actual implementation.
Best Practices and Usage Guidelines
Custom commands should be used only for truly global behavior.
Good use cases:
Opening the application
Global setup or configuration
Test data preparation shared across many tests
What to avoid:
Creating many custom commands
Using them for page-level or test-specific logic
Too many custom commands make the test framework harder to understand, harder to navigate, and harder to maintain.
For most functionality, plain JavaScript helpers, utility functions, or page objects are a better fit.
Additional Notes
Custom commands are accessed via the cy. API
Existing Cypress commands can be overridden, but this is rarely necessary
Advanced features and edge cases are covered in the official Cypress documentation
Rule of thumb:If the behavior is global and reused everywhere, a custom command makes sense. Otherwise, simpler abstractions are usually clearer.