import { test, expect } from '@playwright/test'; test.describe('UAT: 页面加载与基础功能', () => { const corePages = [ { name: '首页', url: '/', titlePattern: /睿新致远/ }, { name: '产品列表', url: '/products', titlePattern: /产品/ }, { name: '服务列表', url: '/services', titlePattern: /服务/ }, { name: '解决方案列表', url: '/solutions', titlePattern: /解决方案/ }, { name: '关于我们', url: '/about', titlePattern: /关于/ }, { name: '联系我们', url: '/contact', titlePattern: /联系/ }, { name: '新闻列表', url: '/news', titlePattern: /新闻/ }, { name: '隐私政策', url: '/privacy', titlePattern: /隐私/ }, { name: '服务条款', url: '/terms', titlePattern: /条款/ }, ]; for (const pageInfo of corePages) { test(`UAT-001: ${pageInfo.name}页面正常加载`, async ({ page }) => { await page.goto(pageInfo.url); await page.waitForLoadState('networkidle'); await expect(page).toHaveTitle(pageInfo.titlePattern); await expect(page.locator('h1')).toBeVisible(); }); } }); test.describe('UAT: 导航组件', () => { test('UAT-010: 顶部导航栏在滚动后样式变化', async ({ page }) => { await page.goto('/'); await page.waitForLoadState('networkidle'); const header = page.locator('header'); await expect(header).toBeVisible(); await page.evaluate(() => window.scrollTo(0, 500)); await page.waitForTimeout(300); await expect(header).toBeVisible(); }); test('UAT-011: 产品Mega Dropdown菜单展开与关闭', async ({ page }) => { await page.goto('/'); await page.waitForLoadState('networkidle'); const productButton = page.locator('nav button:has-text("产品")'); await productButton.click(); await page.waitForTimeout(300); await expect(page.locator('text=财务·采购·销售·库存·生产')).toBeVisible(); await page.keyboard.press('Escape'); await page.waitForTimeout(300); }); test('UAT-012: 解决方案Mega Dropdown菜单展开与关闭', async ({ page }) => { await page.goto('/'); await page.waitForLoadState('networkidle'); const solutionButton = page.locator('nav button:has-text("解决方案")'); await solutionButton.click(); await page.waitForTimeout(300); await expect(page.locator('text=制造业').or(page.locator('text=零售业'))).toBeVisible(); await page.keyboard.press('Escape'); await page.waitForTimeout(300); }); test('UAT-013: Logo点击返回首页', async ({ page }) => { await page.goto('/about'); await page.waitForLoadState('networkidle'); await page.locator('a[aria-label="返回首页"]').click(); await page.waitForLoadState('networkidle'); await expect(page).toHaveURL(/\//); }); }); test.describe('UAT: 产品页面', () => { test('UAT-020: 产品列表页显示所有产品', async ({ page }) => { await page.goto('/products'); await page.waitForLoadState('networkidle'); const productCards = page.locator('a[href*="/products/"]'); const count = await productCards.count(); expect(count).toBeGreaterThanOrEqual(6); }); test('UAT-021: ERP产品详情页正常显示', async ({ page }) => { await page.goto('/products/erp'); await page.waitForLoadState('networkidle'); await expect(page.locator('h1')).toBeVisible(); await expect(page.locator('text=ERP')).toBeVisible(); }); test('UAT-022: CRM产品详情页正常显示', async ({ page }) => { await page.goto('/products/crm'); await page.waitForLoadState('networkidle'); await expect(page.locator('h1')).toBeVisible(); await expect(page.locator('text=CRM')).toBeVisible(); }); test('UAT-023: 产品详情页包含功能特性区域', async ({ page }) => { await page.goto('/products/erp'); await page.waitForLoadState('networkidle'); const featuresSection = page.locator('h2, h3', { hasText: /功能|特性|核心/ }); const count = await featuresSection.count(); expect(count).toBeGreaterThan(0); }); }); test.describe('UAT: 服务页面', () => { const serviceIds = ['software', 'data', 'consulting', 'solutions']; test('UAT-030: 服务列表页显示所有服务', async ({ page }) => { await page.goto('/services'); await page.waitForLoadState('networkidle'); const serviceCards = page.locator('a[href*="/services/"]'); const count = await serviceCards.count(); expect(count).toBeGreaterThanOrEqual(4); }); for (const serviceId of serviceIds) { test(`UAT-031: 服务详情页 ${serviceId} 正常显示`, async ({ page }) => { await page.goto(`/services/${serviceId}`); await page.waitForLoadState('networkidle'); await expect(page.locator('h1')).toBeVisible(); }); } }); test.describe('UAT: 解决方案页面', () => { const solutionIds = ['manufacturing', 'retail', 'education', 'healthcare']; test('UAT-040: 解决方案列表页显示所有方案', async ({ page }) => { await page.goto('/solutions'); await page.waitForLoadState('networkidle'); const solutionCards = page.locator('a[href*="/solutions/"]'); const count = await solutionCards.count(); expect(count).toBeGreaterThanOrEqual(4); }); for (const solutionId of solutionIds) { test(`UAT-041: 解决方案详情页 ${solutionId} 正常显示`, async ({ page }) => { await page.goto(`/solutions/${solutionId}`); await page.waitForLoadState('networkidle'); await expect(page.locator('h1')).toBeVisible(); }); } }); test.describe('UAT: 新闻页面', () => { test('UAT-050: 新闻列表页显示新闻条目', async ({ page }) => { await page.goto('/news'); await page.waitForLoadState('networkidle'); const newsCards = page.locator('a[href*="/news/"]'); const count = await newsCards.count(); expect(count).toBeGreaterThanOrEqual(2); }); test('UAT-051: 新闻详情页 company-founded 正常显示', async ({ page }) => { await page.goto('/news/company-founded'); await page.waitForLoadState('networkidle'); await expect(page.locator('h1', { hasText: '正式成立' })).toBeVisible(); }); test('UAT-052: 新闻详情页 digital-transformation-solution 正常显示', async ({ page }) => { await page.goto('/news/digital-transformation-solution'); await page.waitForLoadState('networkidle'); await expect(page.locator('h1', { hasText: '数字化转型' })).toBeVisible(); }); test('UAT-053: 新闻分类筛选功能', async ({ page }) => { await page.goto('/news'); await page.waitForLoadState('networkidle'); const allNews = page.locator('a[href*="/news/"]'); const initialCount = await allNews.count(); expect(initialCount).toBeGreaterThanOrEqual(2); const companyNewsBtn = page.locator('button:has-text("公司新闻")'); await companyNewsBtn.click(); await page.waitForTimeout(500); const companyFiltered = await allNews.count(); expect(companyFiltered).toBe(1); const productNewsBtn = page.locator('button:has-text("产品发布")'); await productNewsBtn.click(); await page.waitForTimeout(500); const productFiltered = await allNews.count(); expect(productFiltered).toBe(1); const allBtn = page.locator('button:has-text("全部")'); await allBtn.click(); await page.waitForTimeout(500); const restoredCount = await allNews.count(); expect(restoredCount).toBeGreaterThanOrEqual(2); }); test('UAT-054: 新闻搜索功能', async ({ page }) => { await page.goto('/news'); await page.waitForLoadState('networkidle'); const searchInput = page.locator('input[aria-label="搜索新闻"]'); if (await searchInput.isVisible()) { await searchInput.fill('数字化转型'); await page.waitForTimeout(500); const visibleNews = page.locator('a[href*="/news/"]'); const count = await visibleNews.count(); expect(count).toBeGreaterThanOrEqual(1); } }); }); test.describe('UAT: 联系页面', () => { test('UAT-060: 联系页面显示联系信息', async ({ page }) => { await page.goto('/contact'); await page.waitForLoadState('networkidle'); await expect(page.locator('text=contact@novalon.cn')).toBeVisible(); await expect(page.locator('text=成都市龙泉驿区')).toBeVisible(); }); test('UAT-061: 联系表单所有必填字段标记正确', async ({ page }) => { await page.goto('/contact'); await page.waitForLoadState('networkidle'); const requiredFields = page.locator('input[required], textarea[required]'); const count = await requiredFields.count(); expect(count).toBe(5); }); test('UAT-062: 联系表单提交按钮状态', async ({ page }) => { await page.goto('/contact'); await page.waitForLoadState('networkidle'); const submitButton = page.locator('[data-testid="submit-button"]'); await expect(submitButton).toBeVisible(); await expect(submitButton).toBeEnabled(); }); }); test.describe('UAT: 关于页面', () => { test('UAT-070: 关于页面显示公司信息', async ({ page }) => { await page.goto('/about'); await page.waitForLoadState('networkidle'); await expect(page.locator('h1')).toBeVisible(); }); test('UAT-071: 关于页面包含团队信息', async ({ page }) => { await page.goto('/about'); await page.waitForLoadState('networkidle'); const teamSection = page.locator('h2, h3', { hasText: /团队|成员/ }); const count = await teamSection.count(); if (count > 0) { expect(count).toBeGreaterThan(0); } }); }); test.describe('UAT: Cookie同意机制', () => { test('UAT-080: Cookie横幅首次访问时显示', async ({ page }) => { await page.goto('/'); await page.waitForLoadState('networkidle'); await expect(page.locator('text=我们使用 Cookie')).toBeVisible(); await expect(page.locator('button:has-text("管理偏好")')).toBeVisible(); await expect(page.locator('button:has-text("仅必要")')).toBeVisible(); await expect(page.locator('button:has-text("接受所有")')).toBeVisible(); }); test('UAT-081: Cookie偏好设置弹窗功能', async ({ page }) => { await page.goto('/'); await page.waitForLoadState('networkidle'); await page.locator('button:has-text("管理偏好")').click(); await page.waitForTimeout(300); await expect(page.locator('text=Cookie 偏好设置')).toBeVisible(); await expect(page.locator('text=必要 Cookie')).toBeVisible(); await expect(page.locator('text=分析 Cookie')).toBeVisible(); await expect(page.locator('text=营销 Cookie')).toBeVisible(); }); test('UAT-082: 必要Cookie不可取消', async ({ page }) => { await page.goto('/'); await page.waitForLoadState('networkidle'); await page.locator('button:has-text("管理偏好")').click(); await page.waitForTimeout(300); const necessaryCheckbox = page.locator('input[type="checkbox"]').first(); expect(await necessaryCheckbox.isChecked()).toBe(true); expect(await necessaryCheckbox.isDisabled()).toBe(true); }); }); test.describe('UAT: 404错误页面', () => { test('UAT-090: 不存在的页面显示404', async ({ page }) => { await page.goto('/this-page-does-not-exist'); await page.waitForLoadState('networkidle'); await expect(page.locator('text=404')).toBeVisible(); await expect(page.locator('text=页面未找到')).toBeVisible(); }); test('UAT-091: 404页面提供导航建议', async ({ page }) => { await page.goto('/this-page-does-not-exist'); await page.waitForLoadState('networkidle'); await expect(page.locator('text=您可能在寻找')).toBeVisible(); await expect(page.locator('a:has-text("关于我们")')).toBeVisible(); await expect(page.locator('a:has-text("产品")')).toBeVisible(); }); test('UAT-092: 404页面返回首页功能', async ({ page }) => { await page.goto('/this-page-does-not-exist'); await page.waitForLoadState('networkidle'); await page.locator('a:has-text("返回首页")').click(); await page.waitForLoadState('networkidle'); await expect(page).toHaveURL(/\//); }); }); test.describe('UAT: 页脚组件', () => { test('UAT-100: 页脚显示公司版权信息', async ({ page }) => { await page.goto('/'); await page.waitForLoadState('networkidle'); await expect(page.locator('text=四川睿新致远科技有限公司')).toBeVisible(); }); test('UAT-101: 页脚显示备案信息', async ({ page }) => { await page.goto('/'); await page.waitForLoadState('networkidle'); await expect(page.locator('text=蜀ICP备')).toBeVisible(); }); test('UAT-102: 页脚快速导航链接可用', async ({ page }) => { await page.goto('/'); await page.waitForLoadState('networkidle'); const footerNavLinks = page.locator('footer a'); const count = await footerNavLinks.count(); expect(count).toBeGreaterThanOrEqual(5); }); }); test.describe('UAT: 可访问性基础', () => { test('UAT-110: 页面有跳转到主内容的链接', async ({ page }) => { await page.goto('/'); await page.waitForLoadState('networkidle'); const skipLink = page.locator('a:has-text("跳转到主内容")'); await expect(skipLink).toBeAttached(); }); test('UAT-111: 导航区域有正确的ARIA标签', async ({ page }) => { await page.goto('/'); await page.waitForLoadState('networkidle'); const mainNav = page.locator('nav[aria-label="主导航"]'); await expect(mainNav).toBeAttached(); }); test('UAT-112: 图片有alt文本', async ({ page }) => { await page.goto('/'); await page.waitForLoadState('networkidle'); const images = page.locator('img'); const count = await images.count(); for (let i = 0; i < count; i++) { const alt = await images.nth(i).getAttribute('alt'); expect(alt).toBeTruthy(); } }); }); test.describe('UAT: 响应式设计', () => { test('UAT-120: 移动端导航菜单可打开', async ({ page }) => { await page.setViewportSize({ width: 375, height: 667 }); await page.goto('/'); await page.waitForLoadState('networkidle'); const menuButton = page.locator('button[aria-label="打开菜单"]').or( page.locator('button[aria-label="关闭菜单"]') ); if (await menuButton.isVisible()) { await menuButton.click(); await page.waitForTimeout(300); } }); test('UAT-121: 桌面端导航菜单直接显示', async ({ page }) => { await page.setViewportSize({ width: 1280, height: 720 }); await page.goto('/'); await page.waitForLoadState('networkidle'); const desktopNav = page.locator('nav[aria-label="主导航"]'); await expect(desktopNav).toBeVisible(); }); }); test.describe('UAT: 页面标题与SEO', () => { const titlePages = [ { name: '产品列表', url: '/products' }, { name: '服务列表', url: '/services' }, { name: '解决方案', url: '/solutions' }, { name: '关于我们', url: '/about' }, { name: '联系我们', url: '/contact' }, { name: '新闻动态', url: '/news' }, { name: '隐私政策', url: '/privacy' }, { name: '服务条款', url: '/terms' }, ]; for (const pageInfo of titlePages) { test(`UAT-130: ${pageInfo.name}页面标题无重复公司名`, async ({ page }) => { await page.goto(pageInfo.url); await page.waitForLoadState('networkidle'); const title = await page.title(); const companyNameCount = (title.match(/四川睿新致远科技有限公司/g) || []).length; expect(companyNameCount).toBeLessThanOrEqual(1); }); } for (const pageInfo of titlePages) { test(`UAT-131: ${pageInfo.name}页面标题使用简体品牌名`, async ({ page }) => { await page.goto(pageInfo.url); await page.waitForLoadState('networkidle'); const title = await page.title(); expect(title).not.toContain('睿新致遠'); }); } }); test.describe('UAT: 品牌名一致性', () => { test('UAT-140: 视觉展示使用繁体品牌名(配合青柳隷書字体)', async ({ page }) => { await page.goto('/'); await page.waitForLoadState('networkidle'); const brandElement = page.locator('.font-brand').first(); if (await brandElement.isVisible()) { const text = await brandElement.textContent(); expect(text).toContain('睿新致遠'); } }); test('UAT-141: SEO元数据使用简体品牌名', async ({ page }) => { await page.goto('/'); await page.waitForLoadState('networkidle'); const metaDescription = await page.locator('meta[name="description"]').getAttribute('content'); if (metaDescription) { expect(metaDescription).not.toContain('睿新致遠'); } }); test('UAT-142: 结构化数据使用完整公司名', async ({ page }) => { await page.goto('/'); await page.waitForLoadState('networkidle'); const ldJsonScripts = page.locator('script[type="application/ld+json"]'); const count = await ldJsonScripts.count(); if (count > 0) { const content = await ldJsonScripts.first().textContent(); const schema = JSON.parse(content || '{}'); expect(schema.name).toBe('四川睿新致远科技有限公司'); } }); });