E2E and Component Testing

Best practices for End-to-End testing with Playwright and Component testing.

j4flmao Updated

File contents

E2E & Component Testing (Playwright)

Use Playwright for both robust end-to-end testing across modern engines and component testing.

E2E Testing Snippet

import { test, expect } from '@playwright/test';

test('user login flow', async ({ page }) => {
  await page.goto('/login');
  await page.fill('[data-testid="username-input"]', 'testuser');
  await page.fill('[data-testid="password-input"]', 'password');
  await page.click('[data-testid="login-button"]');
  await expect(page.locator('.dashboard')).toBeVisible();
});

Component Testing Snippet

import { test, expect } from '@playwright/experimental-ct-react';
import { Button } from './Button';

test('renders correctly', async ({ mount }) => {
  const component = await mount(<Button>Click me</Button>);
  await expect(component).toContainText('Click me');
  await component.click();
});

Testing Strategy

%%{init: {"theme": "default", "flowchart": {"useMaxWidth": true}}}%%
graph TD
    A[Test Suite] --> B(E2E Tests)
    A --> C(Component Tests)
    B --> D[Browser Farm]
    C --> E[Headless Runner]

j4flmao/agent-skills/tree/main/skills/frontend/e2e-testing commit 91fc6d37b0

Frequently asked questions

npx skillmds@latest add j4flmao/e2e-and-component-testing