一级导航改「行业 × 能力 + 洞察」+ 首页收 8 段之后,旧锚点若不改,
**"绿"只代表还在测上一版信息架构**。本轮 `test:all` 首次跑出
40 failed / 10 例 × 4 project,全部是三组旧断言,逐条按实测 DOM 重写后转绿。
取证方式:不用记忆猜选择器。探针 7 份存
`docs/acceptance/2026-10-17-ia-e2e/probe-*.mjs`,读数是写断言的唯一依据。
关键实测事实:
- hydration 后一级恰为 `['行业','能力','洞察']` 三个
`button[aria-expanded]` + 1 个 `<a href="/about">`
⇒ **桌面顶栏只有 1 个 `<a>`**,这是 p2 那条「取前两个链接」
在 idx=1 稳定读不到元素的根因
- `aria-controls` 在关闭态**故意不渲染**(面板仅 isOpen 时挂载,
header.tsx:178),所以它不能当锚点;定位口径统一为 `button[aria-expanded]`
- 首页实际 testid:`hero-cta`(不是 `hero-primary-cta`)、
`home-ledger{,-metrics,-signals}`、`metrics-basis-note`、
`results-slot-{co-creation,placeholder}`、
`home-{insights,industries,capabilities,cta,cta-button}`;
`trust-section` / `narrative-section` / `cases-co-creation-cta` /
`hero-secondary-link` **已不存在**
- 首页「数据来源」字样实测 **0 次**,口径角注真实文案是
「目标口径,非既成结果」
逐文件:
1. `nav-dropdown.spec.ts` — 两条旧例(产品 / 解决方案下拉)重写为三轴各一条,
并**新增一条一级 IA 契约断言**:触发器文本恰为 `['行业','能力','洞察']`
且「产品」不得回到一级(若 CMS 旧行重新接管导航即判红,
与 navigation-resolution 的代码守卫配对)。
「产品」那条的语义同时升级为**降级后仍可到达**:
能力面板里的「产品矩阵总览 → /products」。
2. `p6-missing-paths.spec.ts` — 产品路径改走 能力 → 产品矩阵总览。
3. `uj-11-home-conversion.spec.ts` — 7 条全重写。四处口径变化逐条写了理由:
双 CTA 收成单 CTA;trust-section 拆成「量化项 / 定性项分列」
(成都·全流程·共创根本不是数字);
**「数据来源」断言改为「口径标注存在且非空」而不是锁措辞** ——
锁字符串会在 target 升到 verified 时误红,
判据要对那一维的存在性敏感而非对文案敏感;
原「叙事区 01/02/03」整段删除,其语义由**成果槽的可判别空态**承接
(既验"有过程叙事",也验"没有假案例",比原断言更强)。
4. `p2-functional-e2e.spec.ts` — 四条旧锚点重写;
「导航链接可点击」改为**按导航自己声明的目的地去走**
(直链优先,未展开的下拉先 hover 再取面板链接),
桌面/移动共用同一条判据,不再硬编码元素类型。保留 N-27 纪律:
不许静默跳过、不许 `waitForURL(...).catch(() => {})` 把"点了没跳转"吞成绿灯。
5. `p5-edge-cases.spec.ts:129` — `narrative-section a[href="/products"]` →
`card-products a[href="/products"]`(页脚,不依赖 hover,仍守住 N-27)。
6. `user-journey.spec.ts:216` — UJ-02 的「解决方案」轴改名「行业」,
动作项「查看全部行业」。
我自己新写的断言里也有一条是错的,一并记(§5.40 同族:仪器只在被复用时才坏):
「首页段序 洞察→行业→能力」最初用 `boundingBox().y` 排序,
而那是**视口相对**值,`scrollIntoViewIfNeeded` 后各段都落在同一带区,
实测读数出现 `-0.5` / `-151.8` ⇒ 判不出先后。
改用文档坐标 `getBoundingClientRect().top + scrollY`,
并实测三段读数 **2684 / 3242 / 3995**,确认这条断言不是恒等式。
复跑(全部重定向后读 `$?`):
`nav-dropdown + p6 + uj-11` × **4 project ⇒ 80 passed / 0 failed**;
`p2` × chromium + chromium-mobile ⇒ **96 passed / 0 failed**;
`npm run test:all` ⇒ **EXIT=0**(e2e:fast 59 passed / 25 skipped,
那 16 个 GA4 @critical 仍在 skipped 侧,须 `test:e2e:prod` 才真断言)。
287 lines
12 KiB
TypeScript
287 lines
12 KiB
TypeScript
import { test, expect, type Page } from './fixtures';
|
||
|
||
/**
|
||
* P6: 缺失路径 E2E 测试补充
|
||
*
|
||
* 覆盖范围:
|
||
* 1. 滚动进度条(ScrollProgress)行为
|
||
* 2. 联系表单完整成功提交流程
|
||
* 3. 首页 → 产品列表 → 产品详情完整用户路径
|
||
* 4. 服务详情页滚动进度条
|
||
*/
|
||
|
||
test.setTimeout(60000);
|
||
|
||
// 本套件走桌面导航(desktop-navigation 在 md 断点以下 display:none):
|
||
// 固定桌面视口,使 chromium-mobile 项目也按用例真实语义验证引擎而非布局。
|
||
test.use({ viewport: { width: 1440, height: 900 } });
|
||
|
||
// ==================== 1. 滚动进度条测试 ====================
|
||
test.describe('滚动进度条 - 全局组件行为', { tag: '@regression' }, () => {
|
||
|
||
test('页面顶部时进度条缩放为 0', async ({ page }) => {
|
||
await page.goto('/', { waitUntil: 'domcontentloaded', timeout: 30000 });
|
||
await page.waitForTimeout(1500);
|
||
|
||
const progressBar = page.locator('[data-testid="scroll-progress"]');
|
||
await expect(progressBar).toBeVisible();
|
||
|
||
const progressFill = progressBar.locator('> div').first();
|
||
const scale = await progressFill.evaluate((el) => {
|
||
const transform = (el as HTMLElement).style.transform;
|
||
const match = transform.match(/scaleX\(([\d.]+)\)/);
|
||
return match ? parseFloat(match[1]) : 0;
|
||
});
|
||
expect(scale).toBe(0);
|
||
});
|
||
|
||
test('滚动页面时进度条缩放增加', async ({ page }) => {
|
||
await page.goto('/', { waitUntil: 'domcontentloaded', timeout: 30000 });
|
||
await page.waitForTimeout(1500);
|
||
|
||
const progressBar = page.locator('[data-testid="scroll-progress"]');
|
||
const progressFill = progressBar.locator('> div').first();
|
||
|
||
const getScale = () => progressFill.evaluate((el) => {
|
||
const transform = (el as HTMLElement).style.transform;
|
||
const match = transform.match(/scaleX\(([\d.]+)\)/);
|
||
return match ? parseFloat(match[1]) : 0;
|
||
});
|
||
|
||
// 先获取顶部缩放
|
||
const topScale = await getScale();
|
||
|
||
// 滚动到页面底部
|
||
await page.evaluate(() => window.scrollTo(0, document.body.scrollHeight));
|
||
await page.waitForTimeout(500);
|
||
|
||
// 再次获取缩放
|
||
const bottomScale = await getScale();
|
||
|
||
expect(bottomScale).toBeGreaterThan(topScale);
|
||
});
|
||
|
||
test('进度条颜色使用品牌色变量', async ({ page }) => {
|
||
await page.goto('/', { waitUntil: 'domcontentloaded', timeout: 30000 });
|
||
await page.waitForTimeout(1500);
|
||
|
||
const progressFill = page.locator('[data-testid="scroll-progress"] > div').first();
|
||
const background = await progressFill.evaluate((el) => window.getComputedStyle(el).backgroundColor);
|
||
|
||
// 应存在背景色(具体颜色取决于 CSS 变量解析)
|
||
expect(background).toBeTruthy();
|
||
expect(background).not.toBe('rgba(0, 0, 0, 0)');
|
||
});
|
||
});
|
||
|
||
// ==================== 2. 联系表单完整提交流程 ====================
|
||
test.describe('联系表单 - 完整成功提交', { tag: '@regression' }, () => {
|
||
|
||
test.beforeEach(async ({ page }) => {
|
||
await page.goto('/contact', { waitUntil: 'domcontentloaded', timeout: 30000 });
|
||
await page.waitForTimeout(2500);
|
||
|
||
// 关闭 Cookie 同意横幅,避免覆盖底部表单元素导致点击错位
|
||
const acceptAllButton = page.locator('button:has-text("接受所有")').first();
|
||
if (await acceptAllButton.count() > 0 && await acceptAllButton.isVisible()) {
|
||
await acceptAllButton.click();
|
||
await page.waitForTimeout(500);
|
||
}
|
||
});
|
||
|
||
async function fillContactForm(page: Page) {
|
||
await page.locator('[data-testid="name-input"]').fill('测试用户');
|
||
await page.locator('[data-testid="phone-input"]').fill('13800138000');
|
||
await page.locator('[data-testid="email-input"]').fill('test@example.com');
|
||
await page.locator('[data-testid="subject-input"]').fill('E2E 测试咨询');
|
||
await page.locator('[data-testid="message-input"]').fill('这是一条由 Playwright E2E 测试发送的消息。');
|
||
}
|
||
|
||
async function clickSubmitButton(page: Page) {
|
||
const submitButton = page.locator('[data-testid="submit-button"]');
|
||
// 按钮位于页面底部,先滚动到视口并等待布局稳定,避免点击被底部固定栏截获
|
||
await submitButton.scrollIntoViewIfNeeded();
|
||
await page.waitForTimeout(300);
|
||
// 使用原生 DOM click() 触发提交:Playwright 的 locator.click() 在该按钮上会被内部 flex 内容
|
||
// 的命中测试干扰,导致事件未正确冒泡到 form 的 React onSubmit 处理器。
|
||
await page.evaluate(() => {
|
||
const btn = document.querySelector('[data-testid="submit-button"]') as HTMLButtonElement | null;
|
||
btn?.click();
|
||
});
|
||
}
|
||
|
||
test('填写有效信息并提交成功', async ({ page }) => {
|
||
let routeHit = false;
|
||
// 拦截表单提交 API,返回成功响应
|
||
await page.route('/api/contact', async (route) => {
|
||
routeHit = true;
|
||
await route.fulfill({
|
||
status: 200,
|
||
contentType: 'application/json',
|
||
body: JSON.stringify({ success: true, message: '发送成功' }),
|
||
});
|
||
});
|
||
|
||
await fillContactForm(page);
|
||
await clickSubmitButton(page);
|
||
|
||
// 等待成功状态出现
|
||
await page.waitForTimeout(1500);
|
||
|
||
console.log('Route hit in success test:', routeHit);
|
||
|
||
// 验证成功提示或成功状态存在
|
||
const bodyText = await page.locator('body').textContent();
|
||
const hasSuccessIndicator =
|
||
bodyText!.includes('消息已发送') ||
|
||
bodyText!.includes('感谢') ||
|
||
bodyText!.includes('发送成功');
|
||
expect(hasSuccessIndicator).toBe(true);
|
||
});
|
||
|
||
test('提交时显示加载状态', async ({ page }) => {
|
||
let routeHit = false;
|
||
// 延迟 API 响应以观察加载状态
|
||
await page.route('/api/contact', async (route) => {
|
||
routeHit = true;
|
||
await new Promise((resolve) => setTimeout(resolve, 800));
|
||
await route.fulfill({
|
||
status: 200,
|
||
contentType: 'application/json',
|
||
body: JSON.stringify({ success: true, message: '发送成功' }),
|
||
});
|
||
});
|
||
|
||
await fillContactForm(page);
|
||
|
||
const submitButton = page.locator('[data-testid="submit-button"]');
|
||
await submitButton.scrollIntoViewIfNeeded();
|
||
await page.waitForTimeout(300);
|
||
|
||
// 隐藏可能覆盖底部元素的固定返回顶部按钮
|
||
await page.evaluate(() => {
|
||
const backToTop = document.querySelector('[aria-label="返回顶部"]') as HTMLElement | null;
|
||
if (backToTop) backToTop.style.display = 'none';
|
||
});
|
||
|
||
// 使用原生 DOM click() 触发提交,避免 Playwright 命中测试在按钮 flex 内容上失效
|
||
await page.evaluate(() => {
|
||
const btn = document.querySelector('[data-testid="submit-button"]') as HTMLButtonElement | null;
|
||
btn?.click();
|
||
});
|
||
|
||
await page.waitForTimeout(100);
|
||
console.log('disabled 100ms after click:', await submitButton.isDisabled(), 'routeHit:', routeHit);
|
||
|
||
// 提交后立即检查按钮是否被禁用
|
||
await expect(submitButton).toBeDisabled({ timeout: 5000 });
|
||
});
|
||
});
|
||
|
||
// ==================== 3. 完整用户路径 ====================
|
||
test.describe('关键用户路径 - 首页 → 产品 → 详情', { tag: ['@smoke', '@regression'] }, () => {
|
||
|
||
test('从首页导航到产品列表页', async ({ page }) => {
|
||
await page.goto('/', { waitUntil: 'domcontentloaded', timeout: 30000 });
|
||
await page.waitForTimeout(2000);
|
||
|
||
// 2026-10-17 起「产品」退出一级导航(ADR-0008 决策二:一级改行业 × 能力 + 洞察),
|
||
// 到达路径改为「能力 → 产品矩阵组 → 产品矩阵总览 /products」。
|
||
// 这条用例的意义随之从"产品在下拉里"升级为"降级后产品仍可经导航到达"——
|
||
// 降级动作最容易造成的缺陷就是把 /products 变成孤儿。
|
||
const desktopNav = page.locator('[data-testid="desktop-navigation"]').first();
|
||
const capabilitiesDropdown = desktopNav.locator('button:has-text("能力")').first();
|
||
await expect(capabilitiesDropdown).toBeVisible({ timeout: 5000 });
|
||
await capabilitiesDropdown.hover();
|
||
await page.waitForTimeout(300);
|
||
|
||
const productsLink = desktopNav.locator('a[href="/products"]').first();
|
||
await expect(productsLink).toBeVisible({ timeout: 5000 });
|
||
// 鼠标悬停在链接上,防止下拉菜单因 mouseleave 关闭
|
||
await productsLink.hover();
|
||
await page.waitForTimeout(200);
|
||
await productsLink.click();
|
||
|
||
await page.waitForURL(/\/products/, { timeout: 10000 });
|
||
await expect(page).toHaveURL(/\/products/);
|
||
|
||
const pageTitle = page.locator('h1, h2').first();
|
||
await expect(pageTitle).toBeVisible();
|
||
});
|
||
|
||
test('从产品列表页进入产品详情页', async ({ page }) => {
|
||
await page.goto('/products', { waitUntil: 'domcontentloaded', timeout: 30000 });
|
||
await page.waitForTimeout(2000);
|
||
|
||
const productLinks = page.locator('a[href*="/products/"]:not([href$="/products"])');
|
||
const linkCount = await productLinks.count();
|
||
expect(linkCount).toBeGreaterThan(0);
|
||
|
||
const firstProduct = productLinks.first();
|
||
await firstProduct.click();
|
||
|
||
await page.waitForURL(/\/products\/.+/, { timeout: 10000 });
|
||
await expect(page).toHaveURL(/\/products\/.+/);
|
||
|
||
// 详情页应包含返回按钮或产品标题
|
||
const detailContent = page.locator('main').first();
|
||
await expect(detailContent).toBeVisible();
|
||
const detailText = await detailContent.textContent();
|
||
expect(detailText!.length).toBeGreaterThan(100);
|
||
});
|
||
|
||
test('从产品详情页可跳转回产品列表', async ({ page }) => {
|
||
// erp 为 seed 中已发布产品(prisma/dev.db ContentItem slug='erp')。
|
||
// N-27 修复:原守卫 `if (count > 0 && isVisible)` ⇒ 返回链接消失时静默通过。
|
||
// product-detail-content-v3.tsx:97 恒定渲染 data-testid="product-detail-hero-secondary"
|
||
// 的「查看更多产品」CTA(href="/products"),以此做硬断言 + 真跳转。
|
||
await page.goto('/products/erp', { waitUntil: 'domcontentloaded', timeout: 30000 });
|
||
await page.waitForTimeout(2000);
|
||
|
||
const backLink = page.locator('[data-testid="product-detail-hero-secondary"]');
|
||
await expect(backLink).toBeVisible();
|
||
await expect(backLink).toHaveAttribute('href', '/products');
|
||
|
||
await Promise.all([
|
||
page.waitForURL((url) => new URL(url).pathname === '/products', { waitUntil: 'commit', timeout: 15000 }),
|
||
backLink.click(),
|
||
]);
|
||
await expect(page).toHaveURL((url) => url.pathname === '/products');
|
||
});
|
||
});
|
||
|
||
// ==================== 4. 服务详情页滚动进度条 ====================
|
||
test.describe('服务详情页 - 滚动进度条', { tag: '@regression' }, () => {
|
||
|
||
test('服务详情页存在滚动进度条', async ({ page }) => {
|
||
await page.goto('/services', { waitUntil: 'domcontentloaded', timeout: 30000 });
|
||
await page.waitForTimeout(2000);
|
||
|
||
const serviceLinks = page.locator('a[href*="/services/"]:not([href$="/services"])');
|
||
if (await serviceLinks.count() > 0) {
|
||
await serviceLinks.first().click();
|
||
await page.waitForURL(/\/services\/.+/, { timeout: 10000 });
|
||
} else {
|
||
await page.goto('/services/digital-transformation', { waitUntil: 'domcontentloaded', timeout: 30000 });
|
||
await page.waitForTimeout(2000);
|
||
}
|
||
|
||
// 服务详情页应渲染 ScrollProgress
|
||
const progressBar = page.locator('[data-testid="scroll-progress"]');
|
||
await expect(progressBar).toBeVisible();
|
||
|
||
const progressFill = progressBar.locator('> div').first();
|
||
|
||
// 滚动后缩放应变化
|
||
await page.evaluate(() => window.scrollTo(0, document.body.scrollHeight));
|
||
await page.waitForTimeout(500);
|
||
|
||
const scale = await progressFill.evaluate((el) => {
|
||
const transform = (el as HTMLElement).style.transform;
|
||
const match = transform.match(/scaleX\(([\d.]+)\)/);
|
||
return match ? parseFloat(match[1]) : 0;
|
||
});
|
||
expect(scale).toBeGreaterThan(0);
|
||
});
|
||
});
|