E2E Testing with Claude Code: Playwright/Cypress Practical Guide
E2E Testing Claude Code का उपयोग करके. Playwright/Cypress Practical Guide. Includes practical code examples.
E2Etestको Claude Code से Efficient बनाएं
E2E(End-to-End)testはuserの操作フローを自動検証するimportantなtest手法 है।Claude Code का उपयोग करके、PlaywrightやCypressのtestcodeを素早くgenerateし、CI環境へのintegration तक一気に進められ है।
Playwrightでのtestimplementation
logインフローのtest
> logイン सेdashboarddisplay तकのE2Etestを
> Playwrightでबनाओ。Page Objectpatternで。
// 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('pathワード');
this.submitButton = page.getByRole('button', { name: 'logイン' });
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('logインfeatures', () => {
test('सहीauthentication情報でlogインできる', 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('不正なauthentication情報でerrorがdisplayされる', 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('authenticationに失敗しました');
});
});
Cypressでのtestimplementation
ECサイトの購入フロー
> 商品選択 सेcartadd、購入完了 तकのフローを
> Cypressでबनाओ。カスタムcommandも定義して。
// 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('商品をcartにadd करो購入完了できる', () => {
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 の使い分け
| 項目 | Playwright | Cypress |
|---|---|---|
| マルチブラウザ | Chromium/Firefox/WebKit | Chrome/Firefox/Edge |
| 並列実行 | ネイティブsupport | Dashboard利用 |
| マルチtab | support | 非support |
| APItest | support | support |
| 学習コスト | やや高い | 低い |
ビジュアルリグレッションtest
Playwrightのスクリーンショット比較featuresを使えば、UIの意図しない変更を検出でき है।
test('headerの見た目が変わっていないかconfirm', async ({ page }) => {
await page.goto('/');
await expect(page.locator('header')).toHaveScreenshot('header.png');
});
Summary
Claude Code का उपयोग करके、PlaywrightやCypressのE2Etestをefficientlyimplementationし、品質の高いtestスイート build किया जा सकता है。APItestautomationやtest戦略ガイドも合わせてreference के लिए देखें。
詳細はPlaywrightofficial documentationおよびCypressofficial documentationをदेखें。
Related Posts
Claude Code से अपने Side Projects को Supercharge कैसे करें [Examples के साथ]
Claude Code से personal development projects को dramatically speed up करना सीखें। Real-world examples और idea से deployment तक practical workflow शामिल है।
Claude Code से Refactoring कैसे Automate करें
Claude Code से efficiently code refactoring automate करना सीखें। Real-world projects के लिए practical prompts और concrete refactoring patterns शामिल हैं।
Claude Code के साथ Complete CORS Configuration Guide
Claude Code का उपयोग करके complete CORS configuration guide सीखें। Practical tips और code examples शामिल हैं।