From ef056a10e5cbcc3b4951d4c041c19f701bc02eba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E7=BF=94?= Date: Thu, 9 Apr 2026 13:52:51 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=86=92=E7=83=9F?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E8=B6=85=E6=97=B6=E5=92=8C=E5=85=83=E7=B4=A0?= =?UTF-8?q?=E5=AE=9A=E4=BD=8D=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复文件: - e2e/smoke/health-check.spec.ts - e2e/smoke/critical-paths.spec.ts 修复内容: 1. 添加 { waitUntil: 'domcontentloaded' } 选项,避免页面加载超时 2. 使用 getByRole('banner') 替代 locator('header'),避免严格模式冲突 3. 使用 getByRole('navigation').first() 替代 locator('nav'),避免多个导航元素冲突 4. 增加断言超时时间,提高测试稳定性 测试结果: - ✅ 8个冒烟测试全部通过 - ⏱️ 总耗时:9.6秒 - 🚀 测试速度大幅提升 --- e2e/smoke/critical-paths.spec.ts | 18 +++++++++--------- e2e/smoke/health-check.spec.ts | 4 ++-- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/e2e/smoke/critical-paths.spec.ts b/e2e/smoke/critical-paths.spec.ts index 564d20c..6c7bad8 100644 --- a/e2e/smoke/critical-paths.spec.ts +++ b/e2e/smoke/critical-paths.spec.ts @@ -3,15 +3,15 @@ import { testFixtures } from '../fixtures/test-data'; test.describe('关键路径测试 @smoke @critical', () => { test('首页加载正常', async ({ page }) => { - await page.goto('/'); + await page.goto('/', { waitUntil: 'domcontentloaded' }); - await expect(page.locator('header')).toBeVisible(); + await expect(page.getByRole('banner')).toBeVisible(); await expect(page.locator('footer')).toBeVisible(); - await expect(page.locator('nav')).toBeVisible(); + await expect(page.getByRole('navigation').first()).toBeVisible(); }); test('管理员能够登录', async ({ page }) => { - await page.goto('/admin/login'); + await page.goto('/admin/login', { waitUntil: 'domcontentloaded' }); await page.fill('#email', testFixtures.adminUser.email); await page.fill('#password', testFixtures.adminUser.password); await page.click('button[type="submit"]'); @@ -20,19 +20,19 @@ test.describe('关键路径测试 @smoke @critical', () => { }); test('新闻页面可访问', async ({ page }) => { - await page.goto('/news'); + await page.goto('/news', { waitUntil: 'domcontentloaded' }); await expect(page).toHaveURL(/\/news/); - await expect(page.locator('header')).toBeVisible(); + await expect(page.getByRole('banner')).toBeVisible(); }); test('产品页面可访问', async ({ page }) => { - await page.goto('/products'); + await page.goto('/products', { waitUntil: 'domcontentloaded' }); await expect(page).toHaveURL(/\/products/); - await expect(page.locator('header')).toBeVisible(); + await expect(page.getByRole('banner')).toBeVisible(); }); test('联系页面可访问', async ({ page }) => { - await page.goto('/contact'); + await page.goto('/contact', { waitUntil: 'domcontentloaded' }); await expect(page).toHaveURL(/\/contact/); await expect(page.locator('form')).toBeVisible(); }); diff --git a/e2e/smoke/health-check.spec.ts b/e2e/smoke/health-check.spec.ts index bd38933..b68cade 100644 --- a/e2e/smoke/health-check.spec.ts +++ b/e2e/smoke/health-check.spec.ts @@ -2,8 +2,8 @@ import { test, expect } from '@playwright/test'; test.describe('健康检查 @smoke @critical', () => { test('应用能够正常启动', async ({ page }) => { - await page.goto('/'); - await expect(page).toHaveTitle(/四川睿新致远科技有限公司/); + await page.goto('/', { waitUntil: 'domcontentloaded' }); + await expect(page).toHaveTitle(/四川睿新致远科技有限公司/, { timeout: 10000 }); }); test('健康检查API正常', async ({ request }) => {