44 lines
2.6 KiB
Python
44 lines
2.6 KiB
Python
|
|
"""Test offline actual renderer composed HTML and 390px responsiveness."""
|
||
|
|
import json
|
||
|
|
from pathlib import Path
|
||
|
|
from playwright.sync_api import sync_playwright
|
||
|
|
root=Path(__file__).resolve().parents[1]
|
||
|
|
raw=(root/'examples/V8_34_主题Banner与产品卡片_真实渲染交互预览.html').read_text()
|
||
|
|
out=root/'reports/v834';out.mkdir(parents=True,exist_ok=True)
|
||
|
|
results=[]
|
||
|
|
with sync_playwright() as p:
|
||
|
|
browser=p.chromium.launch(executable_path='/usr/bin/chromium',headless=True,args=['--no-sandbox'])
|
||
|
|
page=browser.new_page(viewport={'width':1480,'height':950},device_scale_factor=1)
|
||
|
|
errors=[];page.on('pageerror',lambda err:errors.append(str(err)))
|
||
|
|
page.set_content(raw,wait_until='load')
|
||
|
|
page.locator('#canvas').wait_for()
|
||
|
|
for theme in ['automotive','industrial']:
|
||
|
|
page.locator('#theme').select_option(theme)
|
||
|
|
for variant in ['split','image-first','centered']:
|
||
|
|
page.locator('#banner').select_option(variant)
|
||
|
|
for cards in ['standard','compact','showcase']:
|
||
|
|
page.locator('#cards').select_option(cards)
|
||
|
|
for width in ['100%','390px']:
|
||
|
|
page.locator(f'[data-width="{width}"]').click()
|
||
|
|
page.wait_for_timeout(80)
|
||
|
|
frame=page.frame_locator('#canvas')
|
||
|
|
hero=frame.locator('.sf-hero-grid')
|
||
|
|
item=frame.locator('.sf-section.sf-collection > .sf-container > .sf-collection')
|
||
|
|
assert hero.count()==1,(theme,variant,cards,width)
|
||
|
|
assert item.count()==1,(theme,variant,cards,width)
|
||
|
|
assert f'sf-hero-layout-{variant}' in hero.get_attribute('class')
|
||
|
|
assert f'sf-card-style-{cards}' in item.get_attribute('class')
|
||
|
|
overflow=frame.locator('body').evaluate('(e)=>e.scrollWidth>document.documentElement.clientWidth+1')
|
||
|
|
results.append({'theme':theme,'banner':variant,'cards':cards,'width':width,'overflow':bool(overflow)})
|
||
|
|
# canonical screenshots
|
||
|
|
page.locator('#theme').select_option('industrial');page.locator('#banner').select_option('centered');page.locator('#cards').select_option('showcase');page.locator('[data-width="100%"]').click()
|
||
|
|
page.wait_for_timeout(120)
|
||
|
|
page.screenshot(path=str(out/'v834-desktop.png'),full_page=True)
|
||
|
|
page.locator('[data-width="390px"]').click();page.wait_for_timeout(120)
|
||
|
|
page.screenshot(path=str(out/'v834-phone.png'),full_page=True)
|
||
|
|
assert not errors,errors
|
||
|
|
browser.close()
|
||
|
|
report={'cases':len(results),'overflows':[x for x in results if x['overflow']],'js_errors':errors,'screenshots':['v834-desktop.png','v834-phone.png']}
|
||
|
|
(out/'browser-check.json').write_text(json.dumps(report,indent=2,ensure_ascii=False))
|
||
|
|
print(json.dumps({'cases':len(results),'overflows':len(report['overflows']),'js_errors':errors},ensure_ascii=False))
|