cypress-e2e
Skill2 starsChanged 4 months agoMITView on GitHub
Cypress end-to-end testing patterns for reliable browser-based testing, covering selectors, custom commands, API mocking with cy.intercept, CI configuration, and best practices for deterministic, maintainable E2E test suites. Use when the task involves `Cypress`, `E2E testing`, `cypress.config`, `end-to-end testing`, or `browser testing`.
In this repository43 other files it gives its agents.
- accessibilitySkill
- best-practicesSkill
- brainstormingSkill
- core-web-vitalsSkill
- docker-expertSkill
- drizzle-ormSkill
- elixir-developmentSkill
- eslint-configSkill
- express-apiSkill
- frontend-designSkill
- github-actionsSkill
- go-developmentSkill
- grafana-dashboardsSkill
- grpc-apiSkill
- helm-chartsSkill
- jest-testingSkill
- kubernetes-orchestrationSkill
- makefileSkill
- markdown-a11ySkill
- nothing-designSkill
- performanceSkill
- php-developmentSkill
- pinned-tagSkill
- postgresql-developmentSkill
- pr-creatorSkill
- prettier-formattingSkill
- pydanticSkill
- qwik-developmentSkill
- rails-developmentSkill
- ruby-developmentSkill
- rust-async-patternsSkill
- seoSkill
- skill-creatorSkill
- solidjs-developmentSkill
- sqlalchemySkill
- sql-optimization-patternsSkill
- swift-ios-developmentSkill
- tensorflow-mlSkill
- testing-librarySkill
- trpc-type-safetySkill
- webapp-testingSkill
- web-quality-auditSkill
- zig-developmentSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
14 rules. About 0 are common, 3 are distinctive, and 11 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
11
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 23
Use
data-cyAttributes: NEVER select elements by class name, tag, or content that changes with design or i18n. - Very specific: line 25
No Arbitrary Waits: NEVER use cy.wait(5000). Always wait for specific conditions: route aliases, DOM elements, or assertions that Cypress …
- Very specific: line 29
API-First Setup: Use cy.request() or API calls to set up test state (create users, seed data) instead of navigating through the UI.
- Very specific: line 242
Add data-cy attributes to interactive and assertable elements in your component code.
- Very specific: line 243
Use cy.intercept() to mock APIs for deterministic, fast tests.
- Very specific: line 244
Use cy.request() for test setup (seeding data, authentication) to keep tests fast.
- Very specific: line 245
Wait on aliased routes (cy.wait("@alias")) instead of arbitrary timeouts.
- Very specific: line 246
Run tests in CI with --browser chrome --headless and upload screenshots on failure.
- Very specific: line 251
DON'T use cy.wait(3000) — it makes tests slow and flaky.
- Very specific: line 253
DON'T select elements by CSS class (.btn-primary) or tag (button) — they change with redesigns.
- Distinctive: line 255
DON'T write tests that depend on execution order or data from previous tests.
- Distinctive: line 256
DON'T test third-party UI (OAuth login pages, payment forms) — mock them at the API boundary.
- Very specific: line 257
DON'T use cy.get().then() for simple assertions — Cypress commands retry automatically.
- Distinctive: line 259
DON'T navigate through the UI to set up test state — use API calls.
≈ “Common” is an estimate: at least 1 in 5 of the 213,895 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
When to Use
- Writing end-to-end tests for web applications with Cypress.
- Setting up API mocking with
cy.interceptfor deterministic tests. - Creating reusable custom commands for common workflows.
- Configuring Cypress for CI/CD pipelines.
- Debugging flaky E2E tests or improving test reliability.
Critical Patterns
- Use
data-cyAttributes: NEVER select elements by class name, tag, or content that changes with design or i18n. Use dedicateddata-cyattributes that exist solely for testing. - No Arbitrary Waits: NEVER use
cy.wait(5000). Always wait for specific conditions: route aliases, DOM elements, or assertions that Cypress retries automatically. - Test User Flows, Not Units: E2E tests validate complete workflows (login → navigate → perform action → verify result). For isolated logic, use unit tests.
- API-First Setup: Use
cy.request()or API calls to set up test state (create users, seed data) instead of navigating through the UI. Reserve UI interactions for what you're actually testing. - Each Test Stands Alone: Tests must not depend on previous tests or shared state. Use
beforeEachto set up and clean state for each test.
Code Examples
Test Structure with Selectors
// cypress/e2e/dashboard.cy.ts
describe("Dashboard", () => {
beforeEach(() => {
// Set up state via API — fast and reliable
cy.request("POST", "/api/test/seed", {fixture: "dashboard"});
cy.loginByApi("admin@test.com", "password123");
cy.visit("/dashboard");
});
it("displays project list with correct count", () => {
cy.get("[data-cy=project-list]").should("be.visible");
cy.get("[data-cy=project-card]").should("have.length", 3);
});
it("creates a new project", () => {
cy.get("[data-cy=create-project-btn]").click();
cy.get("[data-cy=project-name-input]").type("New Project");
cy.get("[data-cy=project-form-submit]").click();
// Assert on visible result, not internal state
cy.get("[data-cy=project-card]").should("have.length", 4);
cy.contains("[data-cy=project-card]", "New Project").should("exist");
});
it("filters projects by status", () => {
cy.get("[data-cy=filter-dropdown]").click();
cy.get("[data-cy=filter-option-active]").click();
cy.get("[data-cy=project-card]").should("have.length", 2);
cy.get("[data-cy=active-filter-badge]").should("be.visible");
});
});Custom Commands
// cypress/support/commands.ts
declare global {
namespace Cypress {
interface Chainable {
loginByApi(email: string, password: string): Chainable<void>;
getByDataCy(selector: string): Chainable<JQuery<HTMLElement>>;
}
}
}
// Login via API — skip the UI for non-login tests
Cypress.Commands.add("loginByApi", (email: string, password: string) => {
cy.request("POST", "/api/auth/login", {email, password}).then((resp) => {
window.localStorage.setItem("auth_token", resp.body.token);
});
});
// Shorthand for data-cy selectors
Cypress.Commands.add("getByDataCy", (selector: string) => {
return cy.get(`[data-cy=${selector}]`);
});API Mocking with cy.intercept
describe("User Profile", () => {
it("displays user data from API", () => {
// Intercept and mock the API response
cy.intercept("GET", "/api/users/me", {
statusCode: 200,
body: {
id: "1",
name: "Alice",
email: "alice@test.com",
role: "admin",
},
}).as("getProfile");
cy.visit("/profile");
cy.wait("@getProfile"); // Wait for the specific request
cy.getByDataCy("user-name").should("contain", "Alice");
cy.getByDataCy("user-role").should("contain", "admin");
});
it("handles API errors gracefully", () => {
cy.intercept("GET", "/api/users/me", {
statusCode: 500,
body: {error: "Internal server error"},
}).as("getProfileError");
cy.visit("/profile");
cy.wait("@getProfileError");
cy.getByDataCy("error-message").should("contain", "Something went wrong");
cy.getByDataCy("retry-button").should("be.visible");
});
it("shows loading state while fetching", () => {
cy.intercept("GET", "/api/users/me", (req) => {
req.reply({
delay: 1000,
body: {id: "1", name: "Alice"},
});
}).as("getProfileSlow");
cy.visit("/profile");
cy.getByDataCy("loading-spinner").should("be.visible");
cy.wait("@getProfileSlow");
cy.getByDataCy("loading-spinner").should("not.exist");
});
});Using Fixtures
// cypress/fixtures/users.json
[
{"id": "1", "name": "Alice", "role": "admin"},
{"id": "2", "name": "Bob", "role": "user"}
]
// In test
cy.intercept("GET", "/api/users", {fixture: "users.json"}).as("getUsers");Cypress Configuration
// cypress.config.ts
import {defineConfig} from "cypress";
export default defineConfig({
e2e: {
baseUrl: "http://localhost:3000",
specPattern: "cypress/e2e/**/*.cy.{ts,tsx}",
supportFile: "cypress/support/e2e.ts",
viewportWidth: 1280,
viewportHeight: 720,
video: false, // Enable in CI only
screenshotOnRunFailure: true,
defaultCommandTimeout: 10000,
retries: {
runMode: 2, // Retry in CI
openMode: 0, // No retry in interactive
},
setupNodeEvents(on, config) {
// Plugins, code coverage, etc.
},
},
});CI Configuration (GitHub Actions)
cypress-e2e:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: cypress-io/github-action@v6
with:
build: npm run build
start: npm start
wait-on: "http://localhost:3000"
wait-on-timeout: 120
browser: chrome
env:
CYPRESS_BASE_URL: http://localhost:3000
- uses: actions/upload-artifact@v4
if: failure()
with:
name: cypress-screenshots
path: cypress/screenshotsViewport Testing
describe("Responsive Navigation", () => {
const viewports: Cypress.ViewportPreset[] = ["iphone-6", "ipad-2", "macbook-15"];
viewports.forEach((viewport) => {
it(`renders correctly on ${viewport}`, () => {
cy.viewport(viewport);
cy.visit("/");
if (viewport === "iphone-6") {
cy.getByDataCy("mobile-menu-btn").should("be.visible");
cy.getByDataCy("desktop-nav").should("not.be.visible");
} else {
cy.getByDataCy("desktop-nav").should("be.visible");
}
});
});
});Best Practices
DO
- Add
data-cyattributes to interactive and assertable elements in your component code. - Use
cy.intercept()to mock APIs for deterministic, fast tests. - Use
cy.request()for test setup (seeding data, authentication) to keep tests fast. - Wait on aliased routes (
cy.wait("@alias")) instead of arbitrary timeouts. - Run tests in CI with
--browser chrome --headlessand upload screenshots on failure. - Group related tests by feature in separate spec files.
DON'T
- DON'T use
cy.wait(3000)— it makes tests slow and flaky. Wait for assertions or route aliases instead. - DON'T select elements by CSS class (
.btn-primary) or tag (button) — they change with redesigns. - DON'T write tests that depend on execution order or data from previous tests.
- DON'T test third-party UI (OAuth login pages, payment forms) — mock them at the API boundary.
- DON'T use
cy.get().then()for simple assertions — Cypress commands retry automatically. Use.should()instead. - DON'T navigate through the UI to set up test state — use API calls. Test the flow you're verifying, not the setup.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

