58 lines
1.8 KiB
JavaScript
58 lines
1.8 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();
|
||
|
||
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(0).click();
|
||
await page.waitForTimeout(3500);
|
||
|
||
// 视口截图
|
||
await page.screenshot({ path: 'tmp-pix-1.png', fullPage: false });
|
||
|
||
// 用 dom snapshot(用 canvas 截屏)
|
||
await page.evaluate(() => {
|
||
return new Promise((resolve) => {
|
||
// 强制重排
|
||
document.body.offsetHeight;
|
||
resolve();
|
||
});
|
||
});
|
||
await page.waitForTimeout(500);
|
||
await page.screenshot({ path: 'tmp-pix-2.png', fullPage: false });
|
||
|
||
// 显式滚动到顶部
|
||
await page.evaluate(() => {
|
||
const w = document.querySelector('.content-wrap');
|
||
if (w) w.scrollTop = 0;
|
||
});
|
||
await page.waitForTimeout(500);
|
||
await page.screenshot({ path: 'tmp-pix-3.png', fullPage: false });
|
||
|
||
// 直接用 html2canvas 方式:通过截图 element 方式
|
||
const gxnlptEl = await page.locator('.gxnlpt-page').first();
|
||
await gxnlptEl.screenshot({ path: 'tmp-pix-4.png' });
|
||
|
||
// 强制重排 + 再次截图
|
||
await page.evaluate(() => window.dispatchEvent(new Event('resize')));
|
||
await page.waitForTimeout(500);
|
||
await page.screenshot({ path: 'tmp-pix-5.png', fullPage: false });
|
||
|
||
await browser.close();
|
||
})().catch((e) => {
|
||
console.error('TEST ERROR', e);
|
||
process.exit(1);
|
||
});
|