34 lines
2.0 KiB
Python
34 lines
2.0 KiB
Python
|
|
"""Isolated Chromium smoke of shipped standalone theme comparison; no real server."""
|
||
|
|
import asyncio,json
|
||
|
|
from pathlib import Path
|
||
|
|
from playwright.async_api import async_playwright
|
||
|
|
ROOT=Path(__file__).resolve().parents[1];REPORT=ROOT/'reports/v833';REPORT.mkdir(parents=True,exist_ok=True)
|
||
|
|
async def main():
|
||
|
|
async with async_playwright() as p:
|
||
|
|
browser=await p.chromium.launch(headless=True,executable_path='/usr/bin/chromium',args=['--no-sandbox','--disable-dev-shm-usage'])
|
||
|
|
records=[]
|
||
|
|
for device,width in (('desktop',1365),('phone',390)):
|
||
|
|
page=await browser.new_page(viewport={'width':width,'height':850},device_scale_factor=1)
|
||
|
|
errs=[];page.on('pageerror',lambda e:errs.append(str(e)))
|
||
|
|
html=(ROOT/'examples/V8_33_五套主题真实页面_离线交互预览.html').read_text(encoding='utf-8')
|
||
|
|
await page.set_content(html,wait_until='load',timeout=60000)
|
||
|
|
await page.select_option('#theme','trade-pro')
|
||
|
|
await page.select_option('#page','product')
|
||
|
|
await page.frame_locator('#preview').locator('.sf-tp-product-hero').wait_for(state='visible',timeout=12000)
|
||
|
|
await page.wait_for_timeout(1600)
|
||
|
|
if device=='phone':await page.locator('[data-width="390px"]').click()
|
||
|
|
title=await page.title()
|
||
|
|
count=await page.frame_locator('#preview').locator('.pro-trade-pro').count()
|
||
|
|
overflow=await page.evaluate('document.documentElement.scrollWidth>window.innerWidth')
|
||
|
|
img=REPORT/f'trade-pro-{device}.png'
|
||
|
|
await page.screenshot(path=str(img),full_page=True)
|
||
|
|
assert count>0,(device,'theme body missing')
|
||
|
|
assert not overflow,(device,'overflow')
|
||
|
|
assert not errs,(device,errs)
|
||
|
|
records.append({'device':device,'width':width,'theme_body_found':count,'horizontal_overflow':overflow,'script_errors':errs,'screenshot':str(img.relative_to(ROOT))})
|
||
|
|
await page.close()
|
||
|
|
await browser.close()
|
||
|
|
(REPORT/'browser-results.json').write_text(json.dumps(records,ensure_ascii=False,indent=2),encoding='utf-8')
|
||
|
|
print('Chromium PASS:', records)
|
||
|
|
if __name__=='__main__':asyncio.run(main())
|