43 lines
1.5 KiB
JavaScript
43 lines
1.5 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();
|
||
|
||
// 直接访问 gxnlpt?anchor=content-1(不要先访问 home),看看非 keep-alive 场景是否正常
|
||
await page.goto(`${BASE}/view/mhzc/gxnlpt?anchor=content-1`, { waitUntil: 'networkidle', timeout: 30000 });
|
||
await page.waitForSelector('.gxnlpt-page', { timeout: 20000 });
|
||
await page.waitForTimeout(3500);
|
||
|
||
await page.screenshot({ path: 'tmp-direct-1.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-direct-2.png', fullPage: false });
|
||
|
||
// 在视口顶部 evaluate 一下
|
||
const data = await page.evaluate(() => {
|
||
const outlet = document.querySelector('.portal-route-outlet');
|
||
const child = outlet && outlet.firstElementChild;
|
||
return {
|
||
outletChildCount: outlet ? outlet.children.length : 0,
|
||
childClass: child && child.className,
|
||
contentWrapScrollTop: document.querySelector('.content-wrap').scrollTop,
|
||
url: location.href,
|
||
};
|
||
});
|
||
console.log('data:', JSON.stringify(data));
|
||
|
||
await browser.close();
|
||
})().catch((e) => {
|
||
console.error('TEST ERROR', e);
|
||
process.exit(1);
|
||
});
|