import { test, expect, Page } from '@playwright/test'; test.describe('角色管理集成测试', () => { test.beforeEach(async ({ page }) => { await page.goto('/login'); await page.fill('[data-testid="username-input"] input', 'admin'); await page.fill('[data-testid="password-input"] input', 'admin123456'); await page.click('[data-testid="login-button"]'); await expect(page).toHaveURL(/.*\//, { timeout: 15000 }); await page.goto('/system/role'); await page.waitForLoadState('networkidle'); }); test('角色列表页面 - 应正确显示', async ({ page }) => { await expect(page.locator('[data-testid="role-management-container"], .role-management')).toBeVisible(); await expect(page.locator('table, .el-table')).toBeVisible(); }); test('新增角色 - 成功', async ({ page }) => { const timestamp = Date.now(); const addButton = page.locator('button:has-text("新增"), button:has-text("添加")'); if (await addButton.count() > 0) { await addButton.first().click(); await expect(page.locator('.el-dialog')).toBeVisible(); const nameInput = page.locator('input[placeholder*="角色名"], input[placeholder*="名称"]'); if (await nameInput.count() > 0) { await nameInput.fill(`测试角色_${timestamp}`); } const codeInput = page.locator('input[placeholder*="角色编码"], input[placeholder*="编码"]'); if (await codeInput.count() > 0) { await codeInput.fill(`TEST_ROLE_${timestamp}`); } const submitButton = page.locator('.el-dialog button:has-text("确定"), .el-dialog button:has-text("保存")'); if (await submitButton.count() > 0) { await submitButton.click(); await expect(page.locator('.el-message--success')).toBeVisible({ timeout: 10000 }); } } }); test('编辑角色 - 成功', async ({ page }) => { const editButton = page.locator('table button:has-text("编辑"), .el-table button:has-text("编辑")'); if (await editButton.count() > 0) { await editButton.first().click(); await expect(page.locator('.el-dialog')).toBeVisible(); const submitButton = page.locator('.el-dialog button:has-text("确定"), .el-dialog button:has-text("保存")'); if (await submitButton.count() > 0) { await submitButton.click(); await expect(page.locator('.el-message--success')).toBeVisible({ timeout: 10000 }); } } }); test('删除角色 - 成功', async ({ page }) => { const deleteButton = page.locator('table button:has-text("删除"), .el-table button:has-text("删除")'); if (await deleteButton.count() > 0) { await deleteButton.first().click(); const confirmButton = page.locator('.el-popconfirm button:has-text("确定"), .el-message-box button:has-text("确定")'); if (await confirmButton.count() > 0) { await confirmButton.click(); await expect(page.locator('.el-message--success')).toBeVisible({ timeout: 10000 }); } } }); test('分配权限 - 成功', async ({ page }) => { const permissionButton = page.locator('table button:has-text("权限"), .el-table button:has-text("权限")'); if (await permissionButton.count() > 0) { await permissionButton.first().click(); await expect(page.locator('.el-dialog, .el-drawer')).toBeVisible(); const tree = page.locator('.el-tree'); if (await tree.count() > 0) { const checkbox = tree.locator('.el-checkbox').first(); if (await checkbox.count() > 0) { await checkbox.click(); } } const submitButton = page.locator('.el-dialog button:has-text("确定"), .el-drawer button:has-text("保存")'); if (await submitButton.count() > 0) { await submitButton.click(); } } }); });