29 lines
4.0 KiB
Python
29 lines
4.0 KiB
Python
"""Bounded actual-component grammar/AX check with read-only local adapters, no mutations."""
|
|
import json,re,sys,base64
|
|
from pathlib import Path
|
|
from playwright.sync_api import sync_playwright
|
|
sys.path.insert(0,'/Users/dohertj2/.codex/worktrees/scada-ui-consistency/scadaproj/components/ui-theme/validation/theme-1.0.0/canary')
|
|
from browser_zoom import zoom_browser,set_browser_zoom
|
|
origin=re.search(r'Now listening on: (http://127.0.0.1:\d+)',Path('/tmp/ot14-final-host.log').read_text()).group(1)
|
|
out=Path('docs/ui-consistency/evidence/ot14-final');out.mkdir(exist_ok=True,parents=True);results=[]
|
|
samples=['account','api-keys','certificates','role-grants','reservations','secrets','clusters','overview','cluster-edit','cluster-new','cluster-acls','acl-new','cluster-audit','cluster-redundancy','node-new','namespaces','namespace-new','home','node-edit','acl-edit','namespace-edit']
|
|
with sync_playwright() as p:
|
|
with zoom_browser(p) as (context,worker):
|
|
for sample in samples:
|
|
for width,zoom in [(1440,1),(390,1),(1440,2),(390,2)]:
|
|
page=context.new_page();page.set_viewport_size({'width':width,'height':1000});page.emulate_media(reduced_motion='reduce');errors=[];page.on('pageerror',lambda e:errors.append(str(e)))
|
|
page.goto(origin+'/final-grammar-pilot?sample='+sample,wait_until='networkidle');set_browser_zoom(worker,page,zoom);page.wait_for_timeout(250)
|
|
cdp=context.new_cdp_session(page);ax=cdp.send('Accessibility.getFullAXTree')['nodes'];unnamed=[{'role':n.get('role',{}).get('value'),'node':n.get('backendDOMNodeId')} for n in ax if not n.get('ignored') and n.get('role',{}).get('value') in ['textbox','spinbutton','combobox','checkbox','radio','switch'] and not n.get('name',{}).get('value','').strip()]
|
|
relationships=page.evaluate('''()=>({duplicateIds:[...document.querySelectorAll('[id]')].map(e=>e.id).filter((id,i,ids)=>ids.indexOf(id)!==i),missingDescriptions:[...document.querySelectorAll('[aria-describedby],[aria-labelledby]')].flatMap(e=>['aria-describedby','aria-labelledby'].flatMap(a=>(e.getAttribute(a)||'').split(' ').filter(Boolean).filter(id=>!document.getElementById(id)).map(id=>({tag:e.tagName,id,attribute:a}))))})''')
|
|
regions=[]
|
|
for reg in page.locator('.table-wrap[role=region]').all():
|
|
reg.focus();page.keyboard.press('ArrowRight');regions.append(reg.evaluate('e=>({name:e.getAttribute("aria-label"),focused:e===document.activeElement,width:e.clientWidth,scroll:e.scrollWidth})'))
|
|
geometry=page.evaluate('({width:innerWidth,height:innerHeight,document:document.documentElement.scrollWidth,dpr:devicePixelRatio})');motion=page.locator('.rise').evaluate_all('(es)=>es.every(e=>getComputedStyle(e).animationName==="none"&&Number(getComputedStyle(e).opacity)===1)')
|
|
checks={'oneHeading':page.get_by_role('heading',level=1).count()==1,'noPageOverflow':geometry['document']<=geometry['width'],'fieldsNamed':not unnamed,'idsUnique':not relationships['duplicateIds'],'referencesResolve':not relationships['missingDescriptions'],'namedFocusableRegions':all(r['name'] and r['focused'] for r in regions),'reducedMotionFinal':motion,'noPageErrors':not errors}
|
|
if sample not in ['account','secrets']:checks['pageTitle']='OtOpcUa' in page.title()
|
|
result={'sample':sample,'width':width,'zoom':zoom,'actualViewport':geometry,'title':page.title(),'headings':page.get_by_role('heading',level=1).all_text_contents(),'checks':checks,'unnamedFields':unnamed,'relationships':relationships,'regions':regions,'pageErrors':errors};results.append(result)
|
|
if width==390 or zoom==1:
|
|
page.evaluate('scrollTo(0,0)');raw=cdp.send('Page.captureScreenshot',{'format':'png','fromSurface':True,'captureBeyondViewport':False});(out/f'{sample}-{width}-zoom{zoom}.png').write_bytes(base64.b64decode(raw['data']))
|
|
page.close();(out/'confirmation-grammar-matrix.json').write_text(json.dumps(results,indent=2)+'\n')
|
|
print(json.dumps({'cases':len(results),'passed':sum(all(r['checks'].values()) for r in results),'failures':[r for r in results if not all(r['checks'].values())]},indent=2));assert all(all(r['checks'].values()) for r in results)
|