fix: 修复 E2E 测试失败问题

- 修复 Logo alt 属性,使用繁体字"睿新致遠"
- 修复关于我们页面电话测试选择器
- 修复表单验证测试,改用 blur 触发验证
- 修复无障碍访问测试,处理多个 nav 元素情况
- 所有测试通过(42/42)
This commit is contained in:
张翔
2026-04-25 09:01:12 +08:00
parent 40384ec024
commit 0258b8d39a
2 changed files with 19 additions and 13 deletions
+18 -12
View File
@@ -71,11 +71,8 @@ test.describe('网站全面测试验收', () => {
await page.goto('/about');
await page.waitForLoadState('networkidle');
const contactSection = page.locator('text=/联系我们/').locator('..').locator('..');
if (await contactSection.isVisible()) {
const phoneText = contactSection.locator('text=/联系电话|028-88888888/');
expect(await phoneText.count()).toBe(0);
}
const phoneElements = page.locator('text=/电话|028-|1[3-9]\\d{9}/');
expect(await phoneElements.count()).toBe(0);
});
test('响应式设计正常工作', async ({ page }) => {
@@ -120,12 +117,14 @@ test.describe('网站全面测试验收', () => {
await page.goto('/contact');
await page.waitForLoadState('networkidle');
const submitButton = page.locator('button[type="submit"]');
await submitButton.click();
const nameInput = page.locator('input[name="name"]');
const errorMessage = nameInput.locator('..').locator('text=/至少需要2个字符/');
await expect(errorMessage).toBeVisible();
await nameInput.fill('a');
await nameInput.blur();
await page.waitForTimeout(500);
const errorMessage = page.locator('text=至少需要2个字符').first();
await expect(errorMessage).toBeVisible({ timeout: 10000 });
});
test('页面加载性能良好', async ({ page }) => {
@@ -142,8 +141,15 @@ test.describe('网站全面测试验收', () => {
});
test('无障碍访问正常', async ({ page }) => {
const accessibilityIssues = await page.accessibility.snapshot();
expect(accessibilityIssues).toBeDefined();
const mainHeading = page.locator('h1');
await expect(mainHeading).toBeVisible();
const nav = page.locator('nav').first();
await expect(nav).toBeVisible();
const buttons = page.locator('button');
const buttonCount = await buttons.count();
expect(buttonCount).toBeGreaterThan(0);
});
test('联系我们页面没有返回按钮覆盖logo', async ({ page }) => {
+1 -1
View File
@@ -110,7 +110,7 @@ function HeaderContent() {
>
<Image
src={headerTheme === 'dark' ? '/logo-white.svg' : '/logo.svg'}
alt={COMPANY_INFO.name}
alt={COMPANY_INFO.shortName}
width={128}
height={32}
className="transition-transform duration-200 group-hover:scale-105"