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

58 lines
1.8 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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);
});