import { expect, test } from '@playwright/test' async function authenticate(context: any) { await context.addCookies([{ name: 'Admin-Token', value: 'job-log-test-token', domain: 'localhost', path: '/' }]) } test('单选定时任务后进入对应的持久化执行日志', async ({ page, context }) => { await authenticate(context) await page.route('**/api/**', async route => { const url = new URL(route.request().url()) if (url.pathname.startsWith('/src/api/')) return route.continue() if (url.pathname.endsWith('/api/v1/getinfo')) { return route.fulfill({ json: { code: 200, data: { roles: ['admin'], name: '管理员', avatar: '', introduction: '', permissions: ['job:sysJob:log'] } } }) } if (url.pathname.endsWith('/api/v1/menurole')) { return route.fulfill({ json: { code: 200, data: [{ path: '/schedule', component: 'Layout', visible: '0', menuName: 'Schedule', title: '定时任务', icon: 'time', children: [{ path: 'manage', component: '/schedule/index', visible: '0', menuName: 'ScheduleManage', title: '定时任务' }, { path: 'log', component: '/schedule/log', visible: '1', menuName: 'JobLog', title: '执行日志' }] }] } }) } if (url.pathname.endsWith('/api/v1/sysjob/5/execution-logs')) { return route.fulfill({ json: { code: 200, data: { job: { jobId: 5, jobName: 'SYB 规格 AI 修复', invokeTarget: 'GoAutoSYBSpecAIParse', deleted: false }, items: [{ id: 21, executionId: '00000000-0000-4000-8000-000000000021', jobId: 5, jobName: 'SYB 规格 AI 修复', invokeTarget: 'GoAutoSYBSpecAIParse', triggerType: 'scheduled', status: 'failed', startedAt: '2026-09-02T01:00:00Z', finishedAt: '2026-09-02T01:00:03Z', durationMs: 3000, errorCode: 'JOB_EXECUTION_FAILED', errorMessage: '任务执行失败,请查看受控服务日志' }], total: 1, page: 1, pageSize: 20 } } }) } if (url.pathname.endsWith('/api/v1/sysjob')) { return route.fulfill({ json: { code: 200, data: { list: [{ jobId: 5, jobName: 'SYB 规格 AI 修复', jobGroup: 'GoAuto', cronExpression: '0 0 * * * *', invokeTarget: 'GoAutoSYBSpecAIParse', status: 2, entry_id: 0 }], count: 1 } } }) } return route.fulfill({ json: { code: 200, data: [] } }) }) await page.goto('/#/schedule/manage') const logButton = page.getByRole('button', { name: '日志', exact: true }) await expect(page.getByText('SYB 规格 AI 修复', { exact: true })).toBeVisible() await expect(logButton).toBeDisabled() await page.locator('.el-table__body-wrapper .el-checkbox').first().click() await expect(logButton).toBeEnabled() await logButton.click() await expect(page).toHaveURL(/#\/schedule\/log\?jobId=5$/) await expect(page.getByRole('heading', { name: 'SYB 规格 AI 修复(#5)' })).toBeVisible() await expect(page.getByText('JOB_EXECUTION_FAILED')).toBeVisible() await expect(page.getByText('任务执行失败,请查看受控服务日志')).toBeVisible() })