47 lines
3.0 KiB
Python
47 lines
3.0 KiB
Python
|
|
"""Chromium isolated visual check for industrial features and collection."""
|
||
|
|
import json
|
||
|
|
from pathlib import Path
|
||
|
|
from playwright.sync_api import sync_playwright
|
||
|
|
root=Path(__file__).resolve().parents[1]
|
||
|
|
pagehtml=(root/'examples/v8331-real-built-page.html').read_text()
|
||
|
|
dest=root/'reports/v8331';dest.mkdir(parents=True,exist_ok=True)
|
||
|
|
rows=[]
|
||
|
|
with sync_playwright() as p:
|
||
|
|
browser=p.chromium.launch(headless=True,executable_path='/usr/bin/chromium',args=['--no-sandbox','--disable-dev-shm-usage'])
|
||
|
|
for width in [1440,820,390,375]:
|
||
|
|
page=browser.new_page(viewport={'width':width,'height':920},device_scale_factor=1)
|
||
|
|
errors=[]
|
||
|
|
page.on('pageerror',lambda exc: errors.append(str(exc)))
|
||
|
|
page.set_content(pagehtml,wait_until='load',timeout=30000)
|
||
|
|
page.wait_for_timeout(150)
|
||
|
|
facts=page.evaluate('''() => {
|
||
|
|
const shell=document.querySelector('.pro-custom-content');
|
||
|
|
const outerFeature=document.querySelector('.sf-section.sf-features');
|
||
|
|
const outerList=document.querySelector('.sf-section.sf-collection');
|
||
|
|
const innerFeature=document.querySelector('.sf-section.sf-features .sf-container > .sf-features');
|
||
|
|
const innerList=document.querySelector('.sf-section.sf-collection .sf-container > .sf-collection');
|
||
|
|
const box=el=>el?({x:Math.round(el.getBoundingClientRect().x),width:Math.round(el.getBoundingClientRect().width),display:getComputedStyle(el).display,cols:getComputedStyle(el).gridTemplateColumns}):null;
|
||
|
|
return {bodyScroll:document.documentElement.scrollWidth,viewport:innerWidth,
|
||
|
|
featuresOuter:box(outerFeature),listOuter:box(outerList),featuresInner:box(innerFeature),listInner:box(innerList),
|
||
|
|
featureCount:document.querySelectorAll('.sf-feature').length,
|
||
|
|
productCount:document.querySelectorAll('.sf-item').length,
|
||
|
|
filterCount:document.querySelectorAll('.pro-custom-content .sf-filters').length,
|
||
|
|
module:box(shell)};
|
||
|
|
}''')
|
||
|
|
assert facts['featuresOuter']['display']=='block',facts
|
||
|
|
assert facts['listOuter']['display']=='block',facts
|
||
|
|
assert facts['featuresInner']['display']=='grid',facts
|
||
|
|
assert facts['listInner']['display']=='grid',facts
|
||
|
|
assert facts['featuresInner']['width']>=min(900,width-80),facts
|
||
|
|
assert facts['productCount']==6 and facts['featureCount']==4,facts
|
||
|
|
assert facts['filterCount']==0,facts
|
||
|
|
assert facts['bodyScroll']<=width+1,facts
|
||
|
|
assert not errors,errors
|
||
|
|
shot=dest/f'hesupipe-home-blocks-{width}.png'
|
||
|
|
page.locator('.pro-custom-content').screenshot(path=str(shot),timeout=30000)
|
||
|
|
rows.append({'width':width,'screenshot':shot.name,'facts':facts,'script_errors':errors})
|
||
|
|
page.close()
|
||
|
|
browser.close()
|
||
|
|
(dest/'browser-results.json').write_text(json.dumps(rows,ensure_ascii=False,indent=2))
|
||
|
|
for x in rows:print(x['width'], 'feature grid:',x['facts']['featuresInner']['cols'], 'product grid:', x['facts']['listInner']['cols'], 'filters:',x['facts']['filterCount'])
|