web-testing-cypress-e2e
Cypress E2Eを用いて、テスト構造の設計、データ属性の活用、APIモック、カスタムコマンド、コンポーネントテスト、アクセシビリティテスト、CI/CD連携など、Webアプリケーションのテストを効率的に行うSkill。
📜 元の英語説明(参考)
Cypress E2E testing patterns - test structure, data-cy selectors, cy.intercept() mocking, custom commands, fixtures, component testing, accessibility testing with cypress-axe, and CI/CD integration
🇯🇵 日本人クリエイター向け解説
Cypress E2Eを用いて、テスト構造の設計、データ属性の活用、APIモック、カスタムコマンド、コンポーネントテスト、アクセシビリティテスト、CI/CD連携など、Webアプリケーションのテストを効率的に行うSkill。
※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。
下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o web-testing-cypress-e2e.zip https://jpskill.com/download/10311.zip && unzip -o web-testing-cypress-e2e.zip && rm web-testing-cypress-e2e.zip
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/10311.zip -OutFile "$d\web-testing-cypress-e2e.zip"; Expand-Archive "$d\web-testing-cypress-e2e.zip" -DestinationPath $d -Force; ri "$d\web-testing-cypress-e2e.zip"
完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。
💾 手動でダウンロードしたい(コマンドが難しい人向け)
- 1. 下の青いボタンを押して
web-testing-cypress-e2e.zipをダウンロード - 2. ZIPファイルをダブルクリックで解凍 →
web-testing-cypress-e2eフォルダができる - 3. そのフォルダを
C:\Users\あなたの名前\.claude\skills\(Win)または~/.claude/skills/(Mac)へ移動 - 4. Claude Code を再起動
⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。
🎯 このSkillでできること
下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。
📦 インストール方法 (3ステップ)
- 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
- 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
- 3. 展開してできたフォルダを、ホームフォルダの
.claude/skills/に置く- · macOS / Linux:
~/.claude/skills/ - · Windows:
%USERPROFILE%\.claude\skills\
- · macOS / Linux:
Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。
詳しい使い方ガイドを見る →- 最終更新
- 2026-05-18
- 取得日時
- 2026-05-18
- 同梱ファイル
- 1
📖 Skill本文(日本語訳)
※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。
Cypress E2E テストのパターン
クイックガイド: 完全なユーザーワークフローを検証するエンドツーエンドテストには Cypress を使用します。回復力のあるセレクターには
data-cy属性、決定的な API モックにはエイリアス付きのcy.intercept()(決して任意のcy.wait(ms)は使用しない)、認証のキャッシュにはcy.session()を使用します。各it()ブロックは独立している必要があります。Cypress 15 が現在の安定版です。マルチオリジンテストにはcy.origin()が必須です。
<critical_requirements>
重要: この Skill を使用する前に
すべてのコードは
CLAUDE.mdのプロジェクト規約に従う必要があります (kebab-case、名前付きエクスポート、インポート順、import type、名前付き定数)
(主要なセレクター戦略として data-cy 属性を必ず使用してください - CSS/JS の変更から隔離されます)
(エイリアス付きの cy.intercept() と cy.wait("@alias") を必ず使用してください - 任意の cy.wait(ms) 遅延は絶対に使用しないでください)
(テストを分離する必要があります - 各 it() ブロックは他のテストに依存せずに独立して実行されます)
(異なるオリジンを跨いでナビゲートするテストには、必ず cy.origin() を使用してください - Cypress 14 以降必須)
</critical_requirements>
自動検出: Cypress, cy.visit, cy.get, cy.intercept, cy.origin, cy.session, data-cy, describe, it, beforeEach, cy.fixture, cy.mount, cypress-axe, cy.env
使用すべき時:
- 重要なユーザー向けワークフローのテスト (ログイン、チェックアウト、フォーム送信)
- 複数のページにまたがる複数ステップのユーザージャーニー
- クロスブラウザ互換性テスト
- バックエンド API との実際の統合テスト
cy.mount()を使用した分離されたコンポーネントテスト
使用すべきでない時:
- 純粋なユーティリティ関数のテスト (ユニットテストを使用)
- UI なしの API のみのテスト (直接 API テストを使用)
- 実装の詳細のテスト (リファクタリング時にテストが脆くなる)
カバーされる主要なパターン:
- テスト構造と構成 (describe, context, it)
data-cy属性を使用したセレクター戦略- TypeScript サポート付きのカスタムコマンド
cy.intercept()を使用したネットワークモック- フィクスチャとテストデータ管理
cy.mount()を使用したコンポーネントテストcypress-axeを使用したアクセシビリティテストcy.origin()を使用したマルチオリジンテスト
詳細なリソース:
- examples/core.md - ユーザーフロー、テスト構造、セレクター、アサーション、エイリアス、セッション
- examples/intercept.md - API モック、エラー状態、リクエスト検証、レスポンス変更
- examples/custom-commands.md - カスタムコマンド、TypeScript 型、子/デュアルコマンド
- examples/fixtures-data.md - フィクスチャ、ファクトリ、テストデータ定数
- examples/component-testing.md -
cy.mount()を使用したコンポーネントテスト - examples/accessibility.md -
cypress-axeを使用したアクセシビリティテスト - examples/ci-cd.md - GitHub Actions, Docker, 並列実行
- reference.md - 意思決定フレームワーク、アンチパターン、Cypress 14/15 の変更
<philosophy>
哲学
Cypress E2E テストは、アプリケーションがユーザーの視点から正しく動作することを検証します。アプリケーションと同じランループで実行され、ユーザーに見える動作に関する信頼性の高い、高速なフィードバックを提供します。
コア原則:
- ユーザーに見える動作をテストする - 実装の詳細ではなく、エンドユーザーが見て操作するものに焦点を当てます
- 回復力のあるセレクターを使用する -
data-cy属性は CSS/JS の変更から隔離され、リファクタリング時に壊れることはありません - テストを完全に分離する - 各
it()ブロックは独立している必要があります。共通のセットアップにはbeforeEachを使用します - Cypress のリトライ機能を信頼する - コマンドは自動的にリトライします。任意の
cy.wait(ms)は絶対に使用しないでください - 外部依存関係をモックする - 信頼性を確保するために、サードパーティ API には
cy.intercept()を使用します
E2E テストが最も価値を提供する時:
- 重要なビジネスワークフロー (認証、支払い、コア機能)
- 複数のページまたはコンポーネントにまたがるユーザージャーニー
- 機能ごとに 1 つの「真の」E2E テストによる実際のバックエンド統合のテスト
- クロスブラウザ互換性の検証
E2E テストが最適な選択肢ではない可能性がある時:
- 純粋なユーティリティ関数のテスト (ユニットテストの方が高速で正確です)
- すべてのエッジケースのテスト (ユニットテストとのバランスを取ります。エッジケースにはモックを使用します)
- 実装の詳細のテスト (テストが脆くなり、リファクタリング時に壊れます)
</philosophy>
<patterns>
コアパターン
パターン 1: テスト構造と構成
関連するテストをグループ化するには describe、異なるシナリオには context、個々のテストケースには it を使用します。名前付き定数はマジックストリングを防ぎます。各テストは beforeEach を介して新たに開始されます。
const LOGIN_URL = "/login";
const DASHBOARD_URL = "/dashboard";
const VALID_EMAIL = "user@example.com";
describe("Login Flow", () => {
beforeEach(() => {
cy.visit(LOGIN_URL);
});
context("with valid credentials", () => {
it("redirects to dashboard after successful login", () => {
cy.get("[data-cy=email-input]").type(VALID_EMAIL);
// ...
cy.url().should("include", DASHBOARD_URL);
});
});
});
良い理由: describe/context による論理的なグループ化、beforeEach による分離の確保、名前付き定数、data-cy セレクター
完全なログインフローとグループ化されたテストの例については、examples/core.md パターン 1-2 を参照してください。
パターン 2: セレクター戦略
信頼性の高い要素選択には data-cy 属性を使用します。CSS のリファクタリングに耐え、テストの意図を明確にします。
// BEST: data-cy attributes
cy.get("[data-cy=submit-button]").click();
// ACCEPTABLE: テキストの変更でテストが失敗するはずの場合の cy.contains()
cy.contains("button", "Submit").click();
// AVOID: CSS クラス、ID、DOM 構造 - すべて脆弱
cy.get(".btn-primary").click(); // スタイリングの変更で壊れる
cy.get("div > button:nth-child(2)").click(); // マークアップの変更で壊れる
ボイラープレートを減らすには cy.getBySel() カスタムコマンドを使用します。examples/core.md パターン 3 および examples/custom-commands.md パターン 1 を参照してください。
(原文がここで切り詰められています)
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開
Cypress E2E Testing Patterns
Quick Guide: Use Cypress for end-to-end tests that verify complete user workflows. Use data-cy attributes for resilient selectors, cy.intercept() with aliases for deterministic API mocking (never arbitrary cy.wait(ms)), and cy.session() to cache authentication. Each it() block must be independent. Cypress 15 is current stable; cy.origin() is mandatory for multi-origin tests.
<critical_requirements>
CRITICAL: Before Using This Skill
All code must follow project conventions in CLAUDE.md (kebab-case, named exports, import ordering,
import type, named constants)
(You MUST use data-cy attributes as your primary selector strategy - they are isolated from CSS/JS changes)
(You MUST use cy.intercept() with aliases and cy.wait("@alias") - NEVER use arbitrary cy.wait(ms) delays)
(You MUST isolate tests - each it() block runs independently without depending on other tests)
(You MUST use cy.origin() for any test that navigates across different origins - required since Cypress 14)
</critical_requirements>
Auto-detection: Cypress, cy.visit, cy.get, cy.intercept, cy.origin, cy.session, data-cy, describe, it, beforeEach, cy.fixture, cy.mount, cypress-axe, cy.env
When to use:
- Testing critical user-facing workflows (login, checkout, form submission)
- Multi-step user journeys that span multiple pages
- Cross-browser compatibility testing
- Testing real integration with backend APIs
- Component testing in isolation with cy.mount()
When NOT to use:
- Testing pure utility functions (use unit tests)
- API-only testing without UI (use direct API tests)
- Testing implementation details (tests become brittle on refactoring)
Key patterns covered:
- Test structure and organization (describe, context, it)
- Selector strategies with data-cy attributes
- Custom commands with TypeScript support
- Network mocking with cy.intercept()
- Fixtures and test data management
- Component testing with cy.mount()
- Accessibility testing with cypress-axe
- Multi-origin testing with cy.origin()
Detailed Resources:
- examples/core.md - User flows, test structure, selectors, assertions, aliases, sessions
- examples/intercept.md - API mocking, error states, request verification, response modification
- examples/custom-commands.md - Custom commands, TypeScript types, child/dual commands
- examples/fixtures-data.md - Fixtures, factories, test data constants
- examples/component-testing.md - Component testing with cy.mount()
- examples/accessibility.md - Accessibility testing with cypress-axe
- examples/ci-cd.md - GitHub Actions, Docker, parallel execution
- reference.md - Decision frameworks, anti-patterns, Cypress 14/15 changes
<philosophy>
Philosophy
Cypress E2E tests verify that your application works correctly from the user's perspective. They run in the same run-loop as your application, providing reliable, fast feedback on user-visible behavior.
Core Principles:
- Test user-visible behavior - Focus on what end users see and interact with, not implementation details
- Use resilient selectors - data-cy attributes are isolated from CSS/JS changes and won't break on refactoring
- Isolate tests completely - Each it() block must be independent; use beforeEach for common setup
- Trust Cypress retry-ability - Commands automatically retry; never use arbitrary cy.wait(ms)
- Mock external dependencies - Use cy.intercept() for third-party APIs to ensure reliability
When E2E tests provide the most value:
- Critical business workflows (authentication, payments, core features)
- User journeys spanning multiple pages or components
- Testing real backend integration with one "true" E2E test per feature
- Cross-browser compatibility verification
When E2E tests may not be the best choice:
- Testing pure utility functions (unit tests are faster and more precise)
- Testing every edge case (balance with unit tests; use mocks for edge cases)
- Testing implementation details (tests become brittle and break on refactoring)
</philosophy>
<patterns>
Core Patterns
Pattern 1: Test Structure and Organization
Use describe to group related tests, context for different scenarios, and it for individual test cases. Named constants prevent magic strings. Each test starts fresh via beforeEach.
const LOGIN_URL = "/login";
const DASHBOARD_URL = "/dashboard";
const VALID_EMAIL = "user@example.com";
describe("Login Flow", () => {
beforeEach(() => {
cy.visit(LOGIN_URL);
});
context("with valid credentials", () => {
it("redirects to dashboard after successful login", () => {
cy.get("[data-cy=email-input]").type(VALID_EMAIL);
// ...
cy.url().should("include", DASHBOARD_URL);
});
});
});
Why good: Logical grouping with describe/context, beforeEach ensures isolation, named constants, data-cy selectors
See examples/core.md Pattern 1-2 for complete login flow and grouped test examples.
Pattern 2: Selector Strategies
Use data-cy attributes for reliable element selection. They survive CSS refactoring and make test intent clear.
// BEST: data-cy attributes
cy.get("[data-cy=submit-button]").click();
// ACCEPTABLE: cy.contains() when text change should fail the test
cy.contains("button", "Submit").click();
// AVOID: CSS classes, IDs, DOM structure - all fragile
cy.get(".btn-primary").click(); // Breaks on styling changes
cy.get("div > button:nth-child(2)").click(); // Breaks on markup changes
Use cy.getBySel() custom command to reduce boilerplate. See examples/core.md Pattern 3 and examples/custom-commands.md Pattern 1 for implementation.
Pattern 3: Network Mocking with cy.intercept()
Mock API responses for deterministic, fast tests. Always alias intercepts and wait on the alias.
cy.intercept("GET", "/api/users", {
statusCode: 200,
body: MOCK_USER,
}).as("getUser");
cy.visit("/profile");
cy.wait("@getUser");
cy.getBySel("user-name").should("contain", MOCK_USER.name);
Why good: Tests are deterministic, alias + wait ensures request completed, no arbitrary delays
Test error states with status codes and forceNetworkError: true. See examples/intercept.md for error state testing, request verification, response modification, and pagination patterns.
Pattern 4: Custom Commands with TypeScript
Wrap common flows (login, selectors) in custom commands with type declarations for IDE autocomplete.
// cypress/support/commands.ts
Cypress.Commands.add("login", (email: string, password: string) => {
cy.session([email, password], () => {
cy.visit("/login");
cy.getBySel("email-input").type(email);
cy.getBySel("password-input").type(password);
cy.getBySel("submit-button").click();
cy.url().should("include", "/dashboard");
});
});
Type declarations go in cypress/support/index.d.ts. See examples/custom-commands.md for selector commands, auth commands with cacheAcrossSpecs, form commands, child/dual commands, database task commands, and cy.origin() commands.
Pattern 5: Fixtures and Test Data
Use fixtures for reusable test data, factories for dynamic data.
// Fixture: cy.intercept with fixture file
cy.intercept("GET", "/api/products", { fixture: "products.json" }).as(
"getProducts",
);
// Factory: dynamic data for specific scenarios
const users = createUsers(5);
cy.intercept("GET", "/api/users", { body: users }).as("getUsers");
Why good: Separates test data from test logic, fixtures are reusable, factories generate scenario-specific data
See examples/fixtures-data.md for organized fixture directories, factory patterns, and centralized test constants.
Pattern 6: Multi-Origin Testing with cy.origin()
Cypress 14+ requires cy.origin() for any test that navigates across different origins (scheme + hostname + port). This is mandatory for OAuth, SSO, and cross-domain workflows.
cy.visit("/login");
cy.getBySel("oauth-button").click();
cy.origin(
"https://auth.provider.com",
{ args: { email, password } },
({ email, password }) => {
cy.get("#email").type(email);
cy.get("#password").type(password);
cy.get("#submit").click();
},
);
cy.url().should("include", "/dashboard"); // Back on original origin
Why required: Chrome deprecated document.domain, which Cypress previously used for cross-origin testing.
See examples/custom-commands.md Pattern 7 for reusable OAuth command with session caching.
</patterns>
<red_flags>
RED FLAGS
High Priority Issues:
- Using
cy.wait(5000)with arbitrary milliseconds - causes flaky or slow tests, use cy.intercept() aliases instead - Using CSS selectors like
.btn-primaryor#submit-btn- fragile and break on refactoring, use data-cy - Tests that depend on previous tests - coupled tests fail randomly, each it() must be independent
- Storing values in
constfor later use - Cypress commands are async, use aliases with.as()instead - Not using
cy.origin()for multi-origin tests - required since Cypress 14 due to Chrome's deprecation of document.domain - Using deprecated
Cypress.env()- usecy.env()for secrets,Cypress.expose()for public values (deprecated in v15.10.0, removed in 16)
Medium Priority Issues:
- Not using beforeEach for common setup - leads to duplicated code and inconsistent state
- Overusing cy.contains() for selectors - text changes may not warrant test failure, prefer data-cy
- No network mocking for external APIs - third-party flakiness affects your tests
- Running only in one browser - cross-browser issues go undetected
- Using
Cypress.Commands.overwrite()for queries - useCypress.Commands.overwriteQuery()since Cypress 14
Common Mistakes:
- Hardcoded test data scattered throughout files - use fixtures and named constants
- Testing implementation details instead of user behavior - tests break on refactoring
- Using
after/afterEachfor cleanup - no guarantee it runs, put cleanup in beforeEach - Starting web server within tests with cy.exec() - server process never exits properly
Gotchas & Edge Cases:
- Cypress commands are chainable and async but don't return Promises - use
.then()for values - Fixture files are cached and won't reflect file changes during test - use cy.readFile() for dynamic files
cy.session()caches login state but clears on spec file change - usecacheAcrossSpecs: true(Cypress 12.4+)- cy.intercept() routes are global to test - reset in beforeEach to prevent pollution
- Parallel tests cannot share state - use fixtures and beforeEach for per-test setup
- Chrome 137+ no longer supports
--load-extensionin branded Chrome - use Electron, Chrome for Testing, or Chromium for extensions
</red_flags>
<critical_reminders>
CRITICAL REMINDERS
All code must follow project conventions in CLAUDE.md
(You MUST use data-cy attributes as your primary selector strategy - they are isolated from CSS/JS changes)
(You MUST use cy.intercept() with aliases and cy.wait("@alias") - NEVER use arbitrary cy.wait(ms) delays)
(You MUST isolate tests - each it() block runs independently without depending on other tests)
(You MUST use cy.origin() for any test that navigates across different origins - required since Cypress 14)
Failure to follow these rules will result in flaky tests, false positives, and maintenance nightmares.
</critical_reminders>