import { test, expect } from '@playwright/test'; test.describe('静态页面', () => { const pages = [ { path: '/about', title: '关于宇之然', checks: ['我们的使命', '北京宇之然科技中心'] }, { path: '/privacy', title: '隐私政策', checks: ['隐私政策'] }, { path: '/terms', title: '服务协议', checks: ['服务协议'] }, { path: '/ai-agreement', title: 'AI 服务协议', checks: ['AI 服务协议'] }, ]; for (const { path, title, checks } of pages) { test.describe(`${path}`, () => { test.beforeEach(async ({ page }) => { await page.goto(path); }); test('页面标题正确', async ({ page }) => { await expect(page).toHaveTitle(new RegExp(title)); }); test('页面标题元素存在', async ({ page }) => { const h1 = page.locator('h1'); await expect(h1).toContainText(title); }); for (const check of checks) { test(`包含 "${check}" 内容`, async ({ page }) => { const el = page.getByText(check, { exact: true }); const count = await el.count(); if (count > 1) { await expect(el.first()).toBeVisible(); } else if (count === 0) { await expect(page.locator('main, article, section').filter({ hasText: check })).toBeVisible(); } else { await expect(el).toBeVisible(); } }); } }); } });