Files
novalon-website/e2e/smoke/critical-paths.spec.ts
T
张翔 ef056a10e5 fix: 修复冒烟测试超时和元素定位问题
修复文件:
- 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秒
- 🚀 测试速度大幅提升
2026-04-09 13:52:51 +08:00

40 lines
1.5 KiB
TypeScript

import { test, expect } from '@playwright/test';
import { testFixtures } from '../fixtures/test-data';
test.describe('关键路径测试 @smoke @critical', () => {
test('首页加载正常', async ({ page }) => {
await page.goto('/', { waitUntil: 'domcontentloaded' });
await expect(page.getByRole('banner')).toBeVisible();
await expect(page.locator('footer')).toBeVisible();
await expect(page.getByRole('navigation').first()).toBeVisible();
});
test('管理员能够登录', async ({ page }) => {
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"]');
await expect(page).toHaveURL(/\/admin(?!\/login)/);
});
test('新闻页面可访问', async ({ page }) => {
await page.goto('/news', { waitUntil: 'domcontentloaded' });
await expect(page).toHaveURL(/\/news/);
await expect(page.getByRole('banner')).toBeVisible();
});
test('产品页面可访问', async ({ page }) => {
await page.goto('/products', { waitUntil: 'domcontentloaded' });
await expect(page).toHaveURL(/\/products/);
await expect(page.getByRole('banner')).toBeVisible();
});
test('联系页面可访问', async ({ page }) => {
await page.goto('/contact', { waitUntil: 'domcontentloaded' });
await expect(page).toHaveURL(/\/contact/);
await expect(page.locator('form')).toBeVisible();
});
});