parastoo-dashboards/parastoo_dashboard/audit_mobile.py

47 lines
No EOL
2.3 KiB
Python

import asyncio, json
from playwright.async_api import async_playwright
async def main():
async with async_playwright() as p:
b = await p.chromium.launch(args=["--no-sandbox"])
# iPhone 14 Pro dimensions
pg = await b.new_page(viewport={"width": 393, "height": 852}, device_scale_factor=3,
is_mobile=True, has_touch=True)
errs = []
pg.on("pageerror", lambda e: errs.append(f"ERR {e}"))
pg.on("console", lambda m: errs.append(f"C {m.text}") if m.type == "error" else None)
await pg.goto("https://parastoo.zebellkhan.com/", wait_until="networkidle", timeout=90000)
await pg.wait_for_timeout(3500)
TABS = ["dashboard", "calendar", "weekly", "monthly", "roadmap", "tasks", "team", "remind", "sync"]
out = {}
for t in TABS:
await pg.click(f'#tabs button[data-view="{t}"]')
await pg.wait_for_timeout(2000)
r = await pg.evaluate(f"""() => {{
const v = document.getElementById('view-{t}');
const body = document.body;
return {{
hOverflow: document.documentElement.scrollWidth - document.documentElement.clientWidth,
viewWidth: v ? v.getBoundingClientRect().width : 0,
cards: v ? [...v.querySelectorAll('.card')].map(c => {{
const r = c.getBoundingClientRect();
return {{w: Math.round(r.width), clipped: r.right > document.documentElement.clientWidth + 2}};
}}).filter(c => c.clipped) : [],
tabsScroll: document.getElementById('tabs')?.scrollWidth > document.getElementById('tabs')?.clientWidth,
headerClip: (() => {{
const h = document.querySelector('.top');
return h ? h.scrollWidth > h.clientWidth : false;
}})(),
fontSize: v ? getComputedStyle(v).fontSize : null,
textSample: v ? v.innerText.replace(/\\s+/g,' ').trim().slice(0,60) : ''
}};
}}""")
await pg.screenshot(path=f"/workspace/parastoo_dashboard/audit/mobile_{t}.png", full_page=False)
out[t] = r
print(json.dumps(out, ensure_ascii=False, indent=2))
print("ERRORS:", errs[:5])
await b.close()
asyncio.run(main())