Cypress
Cypress is a next-generation front-end testing tool built for the modern web, enabling fast, easy, and reliable testing for anything that runs in a browser. It supports end-to-end, component, and API testing. The current stable version is 15.14.0, and it maintains a regular release cadence with frequent minor updates and periodic major versions.
Common errors
-
Cypress detected that you are running a very old version of Node.js
cause Your Node.js runtime version does not meet Cypress's minimum requirements.fixUpgrade your Node.js to a version compatible with Cypress (e.g., `^20.1.0 || ^22.0.0 || >=24.0.0`). You might use a tool like NVM (Node Version Manager) to manage multiple Node.js versions. -
Cypress command `cy.route()` is deprecated. Please use `cy.intercept()` instead.
cause You are using an outdated command for network stubbing/spying.fixReplace all instances of `cy.route()` with `cy.intercept()`. Review the Cypress documentation for `cy.intercept()` for detailed usage. -
Timed out retrying: Expected to find element: '...', but never found it.
cause Cypress could not find the specified DOM element within the default command timeout (usually 4 seconds).fixVerify the selector is correct and the element is present in the DOM within the expected time. Add explicit waits using `cy.wait('@alias')` for network requests, increase the command timeout if genuinely needed (`cy.get('selector', { timeout: 10000 })`), or ensure the element is rendered after any asynchronous operations. -
Cypress failed to start. This may be due to a missing or invalid configuration file.
cause Cypress cannot find or correctly parse its configuration file.fixEnsure you have a `cypress.config.js` or `cypress.config.ts` file in your project root, and it's correctly structured using `defineConfig`. If migrating from an older version, rename and update `cypress.json`.
Warnings
- breaking Cypress requires specific Node.js versions. Ensure your Node.js environment meets the minimum requirements.
- gotcha Cypress commands are asynchronous and queued, not immediately executed. They do not return promises directly, which can lead to common JavaScript asynchronous patterns (like `async/await`) not working as expected with `cy` commands.
- breaking Configuration files moved from `cypress.json` to `cypress.config.js` or `cypress.config.ts`.
- breaking The `cy.route()` command for network stubbing has been deprecated and replaced by `cy.intercept()`.
- gotcha Over-reliance on `cy.wait(ms)` for arbitrary time delays can lead to flaky tests, as it doesn't wait for specific conditions to be met.
Install
-
npm install cypress -
yarn add cypress -
pnpm add cypress
Imports
- defineConfig
import { defineConfig } from 'cypress'
Quickstart
import { defineConfig } from 'cypress';
export default defineConfig({
e2e: {
setupNodeEvents(on, config) {
// implement node event listeners here
},
},
});
// cypress/e2e/example.cy.ts
describe('My First Test', () => {
it('Visits the Kitchen Sink', () => {
cy.visit('https://example.cypress.io');
cy.contains('type').click();
cy.url().should('include', '/commands/actions');
cy.get('.action-email')
.type('test@example.com')
.should('have.value', 'test@example.com');
});
});