import { test, expect } from '@playwright/test'; test.describe('审计工作流', () => { test('执行操作并查看操作日志', async ({ page }) => { await test.step('执行产生操作日志的写操作', async () => { await page.goto('/roles'); await page.waitForLoadState('networkidle'); await page.waitForTimeout(1000); const createBtn = page.locator('button:has-text("新增角色")'); await createBtn.waitFor({ state: 'visible', timeout: 5000 }); await createBtn.click(); await page.waitForSelector('.el-dialog', { state: 'visible', timeout: 5000 }); const dialog = page.locator('.el-dialog'); const timestamp = Date.now(); await dialog.locator('input').first().fill(`审计测试角色_${timestamp}`); await dialog.locator('input').nth(1).fill(`audit_test_${timestamp}`); await dialog.locator('.el-input-number .el-input__inner').fill('99'); await page.locator('.el-dialog button:has-text("确定")').click(); await page.waitForSelector('.el-dialog', { state: 'hidden', timeout: 10000 }).catch(() => {}); await page.waitForTimeout(2000); }); await test.step('导航到操作日志', async () => { await page.goto('/dashboard'); await page.waitForLoadState('domcontentloaded'); await page.waitForTimeout(1000); await page.locator('text=审计日志').waitFor({ state: 'visible', timeout: 5000 }); await page.locator('text=审计日志').click(); await page.waitForTimeout(1000); await page.locator('.el-menu-item:has-text("操作日志")').waitFor({ state: 'visible', timeout: 5000 }); await page.locator('.el-menu-item:has-text("操作日志")').click(); await page.waitForLoadState('domcontentloaded'); await page.waitForTimeout(2000); await expect(page).toHaveURL(/.*oplog/, { timeout: 10000 }); await expect(page.locator('.el-table')).toBeVisible({ timeout: 10000 }); }); await test.step('验证操作日志记录', async () => { await page.waitForTimeout(2000); const logContent = await page.locator('.el-table').textContent(); const hasLog = logContent && !logContent.includes('暂无数据'); if (hasLog) { expect(logContent).toMatch(/角色管理|用户管理|菜单管理/); } else { await page.reload(); await page.waitForLoadState('domcontentloaded'); await page.waitForTimeout(3000); const refreshedContent = await page.locator('.el-table').textContent(); expect(refreshedContent).toMatch(/角色管理|用户管理|菜单管理/); } }); }); test('查看登录日志', async ({ page }) => { await test.step('导航到登录日志', async () => { await page.goto('/dashboard'); await page.waitForLoadState('domcontentloaded'); await page.waitForTimeout(1000); await page.locator('text=审计日志').waitFor({ state: 'visible', timeout: 5000 }); await page.locator('text=审计日志').click(); await page.waitForTimeout(1000); await page.locator('.el-menu-item:has-text("登录日志")').waitFor({ state: 'visible', timeout: 5000 }); await page.locator('.el-menu-item:has-text("登录日志")').click(); await page.waitForLoadState('domcontentloaded'); await page.waitForTimeout(1000); await expect(page).toHaveURL(/.*loginlog/, { timeout: 15000 }); }); await test.step('验证登录日志显示', async () => { await expect(page.locator('.el-table')).toBeVisible({ timeout: 10000 }); const logContent = await page.locator('.el-table').textContent(); expect(logContent).toBeTruthy(); expect(logContent.length).toBeGreaterThan(0); }); }); test('搜索和筛选日志', async ({ page }) => { await test.step('导航到操作日志', async () => { await page.goto('/dashboard'); await page.waitForLoadState('domcontentloaded'); await page.waitForTimeout(1000); await page.locator('text=审计日志').waitFor({ state: 'visible', timeout: 5000 }); await page.locator('text=审计日志').click(); await page.waitForTimeout(1000); await page.locator('.el-menu-item:has-text("操作日志")').waitFor({ state: 'visible', timeout: 5000 }); await page.locator('.el-menu-item:has-text("操作日志")').click(); await page.waitForLoadState('domcontentloaded'); await page.waitForTimeout(1000); await expect(page.locator('.el-table')).toBeVisible({ timeout: 10000 }); }); await test.step('按模块筛选', async () => { const moduleSelect = page.locator('.el-select:has-text("模块")'); if (await moduleSelect.isVisible()) { await moduleSelect.click(); await page.locator('.el-select-dropdown__item:has-text("用户管理")').click(); await page.waitForTimeout(1000); } }); await test.step('按时间范围筛选', async () => { const dateRangePicker = page.locator('.el-date-editor'); if (await dateRangePicker.isVisible()) { await dateRangePicker.click(); await page.waitForTimeout(500); } }); await test.step('搜索特定内容', async () => { const searchInput = page.locator('input[placeholder*="搜索"]'); if (await searchInput.isVisible()) { await searchInput.fill('admin'); await page.locator('button:has-text("搜索")').click(); await page.waitForTimeout(1000); } }); }); });