import { test, expect } from '@playwright/test'; test.describe('用户管理 E2E 测试', () => { test.beforeEach(async ({ page }) => { await page.goto('/login'); await page.fill('input[placeholder*="用户名"]', 'admin'); await page.fill('input[type="password"]', 'admin123'); await page.click('button:has-text("登录")'); await page.waitForURL('**/dashboard'); }); test('创建用户完整流程', async ({ page }) => { await page.click('text=用户管理'); await page.waitForURL('**/users'); await page.click('text=创建用户'); const timestamp = Date.now(); const username = `testuser_${timestamp}`; await page.fill('input[name="username"]', username); await page.fill('input[name="email"]', `test_${timestamp}@example.com`); await page.fill('input[name="phone"]', '13800138000'); await page.fill('input[name="password"]', 'Test123!@#'); await page.fill('input[name="confirmPassword"]', 'Test123!@#'); await page.click('button[type="submit"]'); await expect(page.locator('.success-message')).toBeVisible(); await expect(page.locator('table')).toContainText(username); }); test('编辑用户流程', async ({ page }) => { await page.click('text=用户管理'); await page.waitForURL('**/users'); await page.click('table tbody tr:first-child .edit-button'); await page.fill('input[name="email"]', 'updated@example.com'); await page.click('button[type="submit"]'); await expect(page.locator('.success-message')).toBeVisible(); await expect(page.locator('table')).toContainText('updated@example.com'); }); test('删除用户流程', async ({ page }) => { await page.click('text=用户管理'); await page.waitForURL('**/users'); const firstRow = page.locator('table tbody tr:first-child'); const username = await firstRow.locator('td:first-child').textContent(); await firstRow.locator('.delete-button').click(); await page.click('.confirm-dialog .confirm-button'); await expect(page.locator('.success-message')).toBeVisible(); await page.reload(); await expect(page.locator('table')).not.toContainText(username); }); test('搜索用户功能', async ({ page }) => { await page.click('text=用户管理'); await page.waitForURL('**/users'); await page.fill('input[name="keyword"]', 'admin'); await page.click('button[type="search"]'); await expect(page.locator('table')).toContainText('admin'); }); test('分页功能', async ({ page }) => { await page.click('text=用户管理'); await page.waitForURL('**/users'); await page.click('.pagination .next-page'); await expect(page.locator('.pagination .current-page')).toContainText('2'); }); });