51 lines
1.9 KiB
JavaScript
51 lines
1.9 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();
|
|
|
|
// 模拟 真实用户使用:刷新一次后不依赖 keep-alive
|
|
// 第一次访问 gxnlpt
|
|
await page.goto(`${BASE}/view/mhzc/gxnlpt`, { waitUntil: 'networkidle', timeout: 30000 });
|
|
await page.waitForSelector('.gxnlpt-page', { timeout: 20000 });
|
|
await page.waitForTimeout(1500);
|
|
|
|
// 直接访问首页 + 点击, 不等待 keep-alive 命中
|
|
await page.goto(`${BASE}/view/mhzc/home`, { waitUntil: 'networkidle', timeout: 30000 });
|
|
await page.waitForSelector('.capability-section', { timeout: 20000 });
|
|
await page.evaluate(() => {
|
|
const el = document.getElementById('section-capability');
|
|
if (el) el.scrollIntoView({ behavior: 'instant', block: 'start' });
|
|
});
|
|
await page.waitForTimeout(800);
|
|
|
|
// 点击 "碳交易平台"
|
|
await page.locator('.capability-card').nth(1).click();
|
|
await page.waitForFunction(() => location.href.includes('gxnlpt'), { timeout: 5000 });
|
|
await page.waitForTimeout(2000);
|
|
|
|
// 检查实际显示
|
|
const data = await page.evaluate(() => {
|
|
const out = {};
|
|
out.url = location.href;
|
|
out.scrollTop = document.querySelector('.content-wrap').scrollTop;
|
|
const sections = ['content-1', 'content-2', 'content-3', 'content-4', 'content-5'].map((id) => {
|
|
const el = document.getElementById(id);
|
|
return { id, top: el ? Math.round(el.getBoundingClientRect().top) : null };
|
|
});
|
|
out.sections = sections;
|
|
return out;
|
|
});
|
|
console.log('after click 碳交易平台:', JSON.stringify(data, null, 2));
|
|
|
|
await page.screenshot({ path: 'tmp-no-keepalive.png', fullPage: false });
|
|
|
|
await browser.close();
|
|
})().catch((e) => {
|
|
console.error('TEST ERROR', e);
|
|
process.exit(1);
|
|
});
|