Files
Neo-ZQYY/scripts/ops/_h5_scroll0_test.py
2026-03-15 10:15:02 +08:00

38 lines
1.6 KiB
Python
Raw Permalink 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.
"""一次性测试脚本H5 scrollTop=0 截图,用于确认 MCP 截图区域对齐。"""
import asyncio
from pathlib import Path
from playwright.async_api import async_playwright
ROOT = Path(__file__).resolve().parents[2]
async def main():
async with async_playwright() as p:
browser = await p.chromium.launch(headless=True, args=["--hide-scrollbars"])
ctx = await browser.new_context(
viewport={"width": 430, "height": 752}, device_scale_factor=3
)
page = await ctx.new_page()
await page.goto(
"http://127.0.0.1:5500/docs/h5_ui/pages/board-finance.html",
wait_until="load", timeout=15000,
)
await page.wait_for_timeout(2500)
await page.evaluate("""() => {
document.documentElement.style.overflow = 'auto';
document.documentElement.style.scrollbarWidth = 'none';
const s = document.createElement('style');
s.textContent = '::-webkit-scrollbar { display: none !important; }';
document.head.appendChild(s);
}""")
await page.wait_for_timeout(300)
await page.evaluate("() => { window.scrollTo({top: 0, behavior: 'instant'}); }")
await page.wait_for_timeout(500)
out = ROOT / "docs" / "h5_ui" / "screenshots" / "h5-board-finance--scroll0-test.png"
await page.screenshot(path=str(out), full_page=False)
info = await page.evaluate("() => ({ scrollY: window.scrollY, innerH: window.innerHeight })")
print(f"H5 scrollY={info['scrollY']}, innerHeight={info['innerH']}")
print(f"截图保存: {out}")
await browser.close()
asyncio.run(main())