47 lines
1.6 KiB
JavaScript
47 lines
1.6 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 }, deviceScaleFactor: 1 });
|
|
const page = await ctx.newPage();
|
|
|
|
// 不使用 keep-alive
|
|
await page.goto(`${BASE}/view/mhzc/home`, { waitUntil: 'networkidle', timeout: 30000 });
|
|
await page.waitForSelector('.capability-section', { timeout: 20000 });
|
|
|
|
// 滚动到 capability 区域
|
|
await page.evaluate(() => {
|
|
const el = document.getElementById('section-capability');
|
|
if (el) el.scrollIntoView({ behavior: 'instant', block: 'start' });
|
|
});
|
|
await page.waitForTimeout(800);
|
|
|
|
// 用 evaluate 在点击前修改 router 行为,禁用 keep-alive
|
|
// 不行;改用:点击后等久一点,确认 router 完成
|
|
await page.locator('.capability-card').nth(0).click();
|
|
// 等待 URL 变化
|
|
await page.waitForFunction(() => location.href.includes('gxnlpt'), { timeout: 5000 });
|
|
// 等待 gxnlpt-page 真正在视口里
|
|
await page.waitForFunction(() => {
|
|
const el = document.querySelector('.gxnlpt-page');
|
|
if (!el) return false;
|
|
const r = el.getBoundingClientRect();
|
|
return r.top >= -10 && r.top < 200;
|
|
}, { timeout: 5000 });
|
|
await page.waitForTimeout(2000);
|
|
|
|
// 截 viewport
|
|
await page.screenshot({ path: 'tmp-final-1.png', fullPage: false });
|
|
|
|
// 截元素
|
|
const el = await page.locator('.gxnlpt-page').first();
|
|
await el.screenshot({ path: 'tmp-final-2.png' });
|
|
|
|
await browser.close();
|
|
})().catch((e) => {
|
|
console.error('TEST ERROR', e);
|
|
process.exit(1);
|
|
});
|