50 lines
1.7 KiB
JavaScript
50 lines
1.7 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 });
|
|
|
|
// 滚动到 capability 区域
|
|
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();
|
|
|
|
// 不停截图
|
|
for (let i = 0; i < 10; i++) {
|
|
await page.waitForTimeout(1000);
|
|
const info = await page.evaluate(() => {
|
|
const contentWrap = document.querySelector('.content-wrap');
|
|
const gxnlptSidebar = document.querySelector('.gxnlpt-sidebar');
|
|
const home = document.querySelector('.capability-section');
|
|
const content1 = document.getElementById('content-1');
|
|
return {
|
|
url: location.href,
|
|
scrollTop: contentWrap ? contentWrap.scrollTop : null,
|
|
scrollHeight: contentWrap ? contentWrap.scrollHeight : null,
|
|
hasGxnlptSidebar: !!gxnlptSidebar,
|
|
hasHome: !!home,
|
|
content1Top: content1 ? Math.round(content1.getBoundingClientRect().top) : null,
|
|
};
|
|
});
|
|
console.log(`t=${i+1}s`, JSON.stringify(info));
|
|
}
|
|
|
|
await page.screenshot({ path: 'tmp-zoom4.png', fullPage: false });
|
|
|
|
await browser.close();
|
|
})().catch((e) => {
|
|
console.error('TEST ERROR', e);
|
|
process.exit(1);
|
|
});
|