κΈ°λ³Έ νμ΄μ§ ν
μ€νΈ
```typescript
import { test, expect } from '@playwright/test';
test.describe('User Profile Page', () => {
test.beforeEach(async ({ page }) => {
// λ‘κ·ΈμΈ λ° νμ΄μ§ μ κ·Ό
await page.goto('/login');
await page.fill('[data-testid="email"]', 'test@example.com');
await page.fill('[data-testid="password"]', 'password123');
await page.click('[data-testid="login-button"]');
await page.waitForURL('/dashboard');
});
test('should display user profile', async ({ page }) => {
await page.goto('/profile');
await expect(page.locator('[data-testid="user-name"]')).toBeVisible();
await expect(page.locator('[data-testid="user-email"]')).toBeVisible();
});
test('should edit profile successfully', async ({ page }) => {
await page.goto('/profile');
// νΈμ§ λͺ¨λ μ§μ
await page.click('[data-testid="edit-button"]');
// μ΄λ¦ λ³κ²½
await page.fill('[data-testid="name-input"]', 'New Name');
// μ μ₯
await page.click('[data-testid="save-button"]');
// μ±κ³΅ νμΈ
await expect(page.locator('[data-testid="success-toast"]')).toBeVisible();
await expect(page.locator('[data-testid="user-name"]')).toHaveText('New Name');
});
});
```
νΌ μΈν°λμ
ν
μ€νΈ
```typescript
test.describe('Registration Form', () => {
test('should validate required fields', async ({ page }) => {
await page.goto('/register');
// λΉ νΌ μ μΆ
await page.click('[data-testid="submit-button"]');
// μλ¬ λ©μμ§ νμΈ
await expect(page.locator('[data-testid="email-error"]')).toHaveText('μ΄λ©μΌμ μ
λ ₯νμΈμ');
await expect(page.locator('[data-testid="password-error"]')).toHaveText('λΉλ°λ²νΈλ₯Ό μ
λ ₯νμΈμ');
});
test('should show password strength indicator', async ({ page }) => {
await page.goto('/register');
// μ½ν λΉλ°λ²νΈ
await page.fill('[data-testid="password"]', '123');
await expect(page.locator('[data-testid="strength-weak"]')).toBeVisible();
// κ°ν λΉλ°λ²νΈ
await page.fill('[data-testid="password"]', 'StrongP@ss123!');
await expect(page.locator('[data-testid="strength-strong"]')).toBeVisible();
});
test('should handle form submission', async ({ page }) => {
await page.goto('/register');
await page.fill('[data-testid="email"]', 'new@example.com');
await page.fill('[data-testid="password"]', 'SecureP@ss123');
await page.fill('[data-testid="confirm-password"]', 'SecureP@ss123');
await page.check('[data-testid="terms-checkbox"]');
await page.click('[data-testid="submit-button"]');
// μ±κ³΅ νμ΄μ§λ‘ 리λ€μ΄λ νΈ
await page.waitForURL('/register/success');
await expect(page.locator('h1')).toHaveText('κ°μ
μλ£');
});
});
```
μν μ ν ν
μ€νΈ
```typescript
test.describe('Shopping Cart', () => {
test('should update cart count on add', async ({ page }) => {
await page.goto('/products');
// μ΄κΈ° μΉ΄νΈ μλ
await expect(page.locator('[data-testid="cart-count"]')).toHaveText('0');
// μν μΆκ°
await page.click('[data-testid="add-to-cart-1"]');
// μΉ΄νΈ μλ μ
λ°μ΄νΈ
await expect(page.locator('[data-testid="cart-count"]')).toHaveText('1');
});
test('should show loading state during checkout', async ({ page }) => {
await page.goto('/cart');
await page.click('[data-testid="checkout-button"]');
// λ‘λ© μν νμΈ
await expect(page.locator('[data-testid="loading-spinner"]')).toBeVisible();
// μλ£ ν 리λ€μ΄λ νΈ
await page.waitForURL('/checkout/success');
});
});
```
μ κ·Όμ± ν
μ€νΈ
```typescript
test.describe('Accessibility', () => {
test('should be keyboard navigable', async ({ page }) => {
await page.goto('/');
// Tab ν€λ‘ λ€λΉκ²μ΄μ
await page.keyboard.press('Tab');
await expect(page.locator(':focus')).toHaveAttribute('data-testid', 'nav-home');
await page.keyboard.press('Tab');
await expect(page.locator(':focus')).toHaveAttribute('data-testid', 'nav-products');
// Enter ν€λ‘ νμ±ν
await page.keyboard.press('Enter');
await page.waitForURL('/products');
});
test('should have proper ARIA labels', async ({ page }) => {
await page.goto('/');
// μ£Όμ μμ ARIA νμΈ
await expect(page.locator('nav')).toHaveAttribute('aria-label', 'Main navigation');
await expect(page.locator('main')).toHaveAttribute('role', 'main');
await expect(page.locator('footer')).toHaveAttribute('role', 'contentinfo');
});
});
```
λ°μν ν
μ€νΈ
```typescript
test.describe('Responsive Design', () => {
test('should show mobile menu on small screens', async ({ page }) => {
// λͺ¨λ°μΌ λ·°ν¬νΈ
await page.setViewportSize({ width: 375, height: 667 });
await page.goto('/');
// νλ²κ±° λ©λ΄ νμ
await expect(page.locator('[data-testid="mobile-menu-button"]')).toBeVisible();
await expect(page.locator('[data-testid="desktop-nav"]')).not.toBeVisible();
// λ©λ΄ μ΄κΈ°
await page.click('[data-testid="mobile-menu-button"]');
await expect(page.locator('[data-testid="mobile-nav"]')).toBeVisible();
});
test('should show desktop nav on large screens', async ({ page }) => {
// λ°μ€ν¬ν± λ·°ν¬νΈ
await page.setViewportSize({ width: 1280, height: 720 });
await page.goto('/');
await expect(page.locator('[data-testid="desktop-nav"]')).toBeVisible();
await expect(page.locator('[data-testid="mobile-menu-button"]')).not.toBeVisible();
});
});
```