txw/tmp-capability-debug.mjs
2026-06-05 12:54:11 +08:00

68 lines
2.3 KiB
JavaScript

import { chromium } from 'playwright';
const BASE = 'http://localhost:9027';
(async () => {
const browser = await chromium.launch();
const ctx = await browser.newContext({ viewport: { width: 1440, height: 900 } });
const page = await ctx.newPage();
page.on('pageerror', (e) => console.log('[pageerror]', e.message));
page.on('console', (m) => {
const t = m.text();
console.log(`[browser:${m.type()}]`, t);
});
await page.goto(`${BASE}/view/mhzc/home`, { waitUntil: 'networkidle', timeout: 30000 });
await page.waitForSelector('.capability-section', { timeout: 20000 });
console.log('home loaded');
// 滚动到 capability 区域
await page.evaluate(() => {
const el = document.getElementById('section-capability');
if (el) el.scrollIntoView({ behavior: 'instant', block: 'start' });
});
await page.waitForTimeout(800);
// 点击 "碳核算平台"
const cardIndex = 0;
await page.locator('.capability-card').nth(cardIndex).click();
// 多等几秒看是否跳转
await page.waitForTimeout(4000);
console.log('url:', page.url());
// 检查 router-view 内的内容
const data = await page.evaluate(() => {
const outlet = document.querySelector('.portal-route-outlet');
if (!outlet) return { hasOutlet: false };
const child = outlet.firstElementChild;
return {
hasOutlet: true,
hasChild: !!child,
childTag: child ? child.tagName : null,
childClass: child ? child.className : null,
hasGongXingNeng: !!document.querySelector('.gxnlpt-shell'),
hasCapabilitySection: !!document.querySelector('.capability-section'),
hasContent1: !!document.getElementById('content-1'),
bodyText: (document.body.innerText || '').slice(0, 300),
};
});
console.log('data:', data);
await page.screenshot({ path: 'tmp-debug.png', fullPage: false });
// 等待 5s 后再次检查
await page.waitForTimeout(5000);
const data2 = await page.evaluate(() => ({
hasGongXingNeng: !!document.querySelector('.gxnlpt-shell'),
hasCapabilitySection: !!document.querySelector('.capability-section'),
hasContent1: !!document.getElementById('content-1'),
url: location.href,
}));
console.log('data2:', data2);
await browser.close();
})().catch((e) => {
console.error('TEST ERROR', e);
process.exit(1);
});