Use Cases

E2E Testing with Claude Code: Playwright/Cypress Practical Guide

E2E Testing using Claude Code. Playwright/Cypress Practical Guide. Includes practical code examples.

E2Etest dengan Claude Code: efisiensi

E2E(End-to-End)test pengguna operasiフロー 自動verifikasi pentingなtest手法.Claude Code 使えば、PlaywrightやCypress testコード 素早くgenerateし、CI環境へ integrasiま 一気 進められ.

testimplementasi Playwright

loginフローのtest

> login dari dashboardtampilanま dengan E2Etest 
> Playwright dengan pembuatanして。Page Objectpola dengan 。
// tests/pages/LoginPage.ts
import { Page, Locator } from '@playwright/test';

export class LoginPage {
  readonly page: Page;
  readonly emailInput: Locator;
  readonly passwordInput: Locator;
  readonly submitButton: Locator;
  readonly errorMessage: Locator;

  constructor(page: Page) {
    this.page = page;
    this.emailInput = page.getByLabel('メールアドレス');
    this.passwordInput = page.getByLabel('パスワード');
    this.submitButton = page.getByRole('button', { name: 'login' });
    this.errorMessage = page.getByRole('alert');
  }

  async goto() {
    await this.page.goto('/login');
  }

  async login(email: string, password: string) {
    await this.emailInput.fill(email);
    await this.passwordInput.fill(password);
    await this.submitButton.click();
  }
}
// tests/e2e/login.spec.ts
import { test, expect } from '@playwright/test';
import { LoginPage } from '../pages/LoginPage';

test.describe('login機能', () => {
  test('正しい認証情報 login きる', async ({ page }) => {
    const loginPage = new LoginPage(page);
    await loginPage.goto();
    await loginPage.login('[email protected]', 'password123');

    await expect(page).toHaveURL('/dashboard');
    await expect(page.getByText('dashboard')).toBeVisible();
  });

  test('不正な認証情報 error tampilanされる', async ({ page }) => {
    const loginPage = new LoginPage(page);
    await loginPage.goto();
    await loginPage.login('[email protected]', 'wrongpassword');

    await expect(loginPage.errorMessage).toBeVisible();
    await expect(loginPage.errorMessage).toContainText('認証 gagalしま');
  });
});

testimplementasi Cypress

ECサイトの購入フロー

> 商品選択 dari カートpenambahan、購入selesaiま dengan フロー 
> Cypress dengan pembuatanして。カスタムcommand juga definisiして。
// cypress/support/commands.ts
Cypress.Commands.add('login', (email: string, password: string) => {
  cy.session([email, password], () => {
    cy.visit('/login');
    cy.get('[data-cy="email"]').type(email);
    cy.get('[data-cy="password"]').type(password);
    cy.get('[data-cy="submit"]').click();
    cy.url().should('include', '/dashboard');
  });
});

// cypress/e2e/purchase.cy.ts
describe('購入フロー', () => {
  beforeEach(() => {
    cy.login('[email protected]', 'password123');
  });

  it('商品 カート penambahan 購入selesai きる', () => {
    cy.visit('/products');
    cy.get('[data-cy="product-card"]').first().click();
    cy.get('[data-cy="add-to-cart"]').click();
    cy.get('[data-cy="cart-badge"]').should('contain', '1');

    cy.visit('/cart');
    cy.get('[data-cy="checkout-button"]').click();

    cy.get('[data-cy="confirm-order"]').click();
    cy.get('[data-cy="order-complete"]').should('be.visible');
    cy.get('[data-cy="order-number"]').should('exist');
  });
});

使い分け Playwright vs Cypress

項目PlaywrightCypress
マルチbrowserChromium/Firefox/WebKitChrome/Firefox/Edge
並列実行ネイティブdukunganDashboardpemanfaatan
マルチtabdukungan非dukungan
APItestdukungandukungan
学習コストやや高い低い

Visual Regression Testing

Playwright スクリーンショット比較機能 使えば、UI 意図し tidak変更 検出 bisa dilakukan.

test('header 見た目 変わってい tidakかkonfirmasi', async ({ page }) => {
  await page.goto('/');
  await expect(page.locator('header')).toHaveScreenshot('header.png');
});

Summary

Dengan Claude Code, PlaywrightやCypress E2Etest efisien implementasiし、品質 高いtestスイート pembangunan bisa dilakukan.APItestotomatisasitest戦略panduan juga 合わせて参考 .

Untuk 詳細, lihat Playwright公式ドキュメントおよびCypress公式ドキュメント.

#Claude Code #E2Etest #Playwright #Cypress #automation