Cypress
Overview
Cypress is an open-source, JavaScript-based testing tool that runs end-to-end, component, and integration tests directly inside the browser alongside your app. It executes in the same run loop as the page, giving automatic waiting, time-travel snapshots, and direct DOM/network control. Read this when writing E2E or component tests, stubbing network calls, debugging flaky selectors, or configuring the Cypress runner.
Official sources
Install / setup
npm install cypress --save-dev
Source: https://docs.cypress.io/app/get-started/install-cypress (open the runner with npx cypress open; requires Node.js 20.x, 22.x, or >=24.x).
Core concepts
cy commands — chained, retriable async actions like cy.visit(), cy.get(), cy.click().
- Automatic retry/waiting — queries retry until assertions pass, removing most manual waits.
- Selectors — prefer
data-* attributes via cy.get('[data-cy=...]') for stable targeting.
- Fixtures — load static JSON test data with
cy.fixture().
- Network control —
cy.intercept() stubs, spies on, and asserts HTTP requests/responses.
- Component testing — mount framework components in isolation (React, Vue, Angular, Svelte).
- Time-travel — the runner snapshots each command for step-by-step DOM inspection.
- Config —
cypress.config.js defines baseUrl, specs, viewport, and env per testing type.
Best practices
Common pitfalls
- Mixing async/await with
cy chains → use Cypress's command queue and .then(), not promises.
- Tests depend on prior test state → make each spec independent and reset between tests.
- Flaky
cy.wait(5000) sleeps → cy.intercept a route, alias it, and cy.wait('@alias').
Examples
describe('home page', () => {
it('loads and shows the heading', () => {
cy.visit('/');
cy.get('[data-cy=heading]').should('contain', 'Welcome');
});
});
Further reading
Related skills
- ../playwright — alternative cross-browser E2E framework with multi-context support
- ../selenium — WebDriver-based browser automation across languages
- ../puppeteer — lower-level Chrome/Firefox automation library
1---2name: cypress3description: Cypress is a JavaScript end-to-end and component testing tool that runs in a real browser with a time-travel debugger, automatic waiting, and network stubbing; consult when writing E2E or component tests, using cy commands and fixtures, intercepting network requests, or configuring cypress.config.4domain: stack5category: testing6tags: [cypress, e2e, javascript, browser-testing, component-testing, automation, web]7official_sources:8 - https://docs.cypress.io/app/get-started/why-cypress9 - https://github.com/cypress-io/cypress10 - https://www.npmjs.com/package/cypress11verified: 2026-06-1712metadata:13 source: https://skillmd.com/skills/gabriel7silva/cypress14---1516# Cypress1718## Overview19Cypress is an open-source, JavaScript-based testing tool that runs end-to-end, component, and integration tests directly inside the browser alongside your app. It executes in the same run loop as the page, giving automatic waiting, time-travel snapshots, and direct DOM/network control. Read this when writing E2E or component tests, stubbing network calls, debugging flaky selectors, or configuring the Cypress runner.2021## Official sources22- Docs: https://docs.cypress.io/app/get-started/why-cypress23- Repo: https://github.com/cypress-io/cypress24- Install: https://www.npmjs.com/package/cypress2526## Install / setup27```bash28npm install cypress --save-dev29```30Source: https://docs.cypress.io/app/get-started/install-cypress (open the runner with `npx cypress open`; requires Node.js 20.x, 22.x, or >=24.x).3132## Core concepts33- **`cy` commands** — chained, retriable async actions like `cy.visit()`, `cy.get()`, `cy.click()`.34- **Automatic retry/waiting** — queries retry until assertions pass, removing most manual waits.35- **Selectors** — prefer `data-*` attributes via `cy.get('[data-cy=...]')` for stable targeting.36- **Fixtures** — load static JSON test data with `cy.fixture()`.37- **Network control** — `cy.intercept()` stubs, spies on, and asserts HTTP requests/responses.38- **Component testing** — mount framework components in isolation (React, Vue, Angular, Svelte).39- **Time-travel** — the runner snapshots each command for step-by-step DOM inspection.40- **Config** — `cypress.config.js` defines `baseUrl`, specs, viewport, and env per testing type.4142## Best practices43- Target elements with dedicated `data-*` attributes, not CSS/text (https://docs.cypress.io/app/core-concepts/best-practices).44- Do not assign command return values to vars; chain or use aliases (https://docs.cypress.io/app/core-concepts/variables-and-aliases).45- Set state via API/`cy.request` or tasks rather than UI for speed (https://docs.cypress.io/app/core-concepts/best-practices).46- Avoid arbitrary `cy.wait(ms)`; wait on aliased routes instead (https://docs.cypress.io/api/commands/wait).4748## Common pitfalls49- Mixing async/await with `cy` chains → use Cypress's command queue and `.then()`, not promises.50- Tests depend on prior test state → make each spec independent and reset between tests.51- Flaky `cy.wait(5000)` sleeps → `cy.intercept` a route, alias it, and `cy.wait('@alias')`.5253## Examples54```js55describe('home page', () => {56 it('loads and shows the heading', () => {57 cy.visit('/');58 cy.get('[data-cy=heading]').should('contain', 'Welcome');59 });60});61```6263## Further reading64- https://docs.cypress.io/api/table-of-contents — full command and assertion API65- https://docs.cypress.io/app/core-concepts/best-practices — official best-practices guide6667## Related skills68- ../playwright — alternative cross-browser E2E framework with multi-context support69- ../selenium — WebDriver-based browser automation across languages70- ../puppeteer — lower-level Chrome/Firefox automation library