"""Exercise actual V8.32 editor HTML/CSS/JS with deterministic same-page mock data. Not an authenticated back-end browser E2E (Chromium container blocks local network). """ from pathlib import Path import json,re from playwright.sync_api import sync_playwright ROOT=Path(__file__).resolve().parents[1] OUT=ROOT/'reports/v832' OUT.mkdir(parents=True,exist_ok=True) source=(ROOT/'app/templates/editor.html').read_text(encoding='utf-8') source=re.sub(r']+src="[^"]+"[^>]*>','',source) source=re.sub(r']+href="/ui/[^"]+"[^>]*>','',source) js=(ROOT/'app/static/editor.js').read_text(encoding='utf-8').replace('const siteId=pathParts[1],initialPage=pathParts[2];',"const siteId='demo',initialPage='p1';") schema={'blocks':{ 'hero':{'name':'大图横幅','icon':'▧','description':'网站首页顶部横幅','fields':['title','subtitle','image'],'defaults':{'title':'HESU AUTO','subtitle':'连接中国汽车与全球市场','image':''}}, 'richtext':{'name':'文字介绍','icon':'▤','description':'企业介绍文字','fields':['title','description'],'defaults':{'title':'关于我们','description':'车辆出口服务'}}, 'collection':{'name':'车型列表','icon':'▦','description':'展示产品与车型','fields':['title'],'defaults':{'title':'精选车型'}}, 'layout':{'name':'多列布局','icon':'◫','fields':['title'],'defaults':{'title':'两列布局','columns':[{'width':1,'blocks':[]},{'width':1,'blocks':[]}]}} },'page_templates':{'standard':{'name':'标准页面'}}} errors=[] with sync_playwright() as p: browser=p.chromium.launch(executable_path='/usr/bin/chromium',args=['--no-sandbox','--disable-dev-shm-usage'],headless=True) page=browser.new_page(viewport={'width':1440,'height':900},device_scale_factor=1) page.on('pageerror',lambda err:errors.append(str(err))) page.set_content(source) page.add_style_tag(content=(ROOT/'app/static/editor.css').read_text(encoding='utf-8')) page.add_script_tag(content=(ROOT/'app/static/editor-helpers.js').read_text(encoding='utf-8')) page.add_script_tag(content=(ROOT/'app/static/studio-experience-v829.js').read_text(encoding='utf-8')) page.evaluate('''(schema)=>{ window.fetch=async function(url,options={}){ const path=String(url).split('?')[0]; if(path.startsWith('/api/factory/themes/')){ const ok=window.__previewOk!==false; return {ok,status:ok?200:503,headers:{get:()=>ok?'text/html':'text/plain'},text:async()=>'

主题预览

'}; } if(path.endsWith('/editor-preview'))return {ok:true,status:200,headers:{get:()=> 'text/html'},text:async()=>`
GLOBAL AUTO EXPORT

中国汽车供应
连接全球市场

从车型采购到国际物流与海外交付的一站式出口服务。

精选车型

ROX 01Luxury SUV
DONGFENG Z9Pickup Truck
BYD YUAN UPElectric Vehicle
`}; const data={ '/api/auth/me':{csrf:'demo'}, '/api/sites/demo':{id:'demo',name:'汽车演示站',theme:'automotive'}, '/api/sites/demo/entries':[{id:'p1',title:'首页',route:'/'}], '/api/editor/blocks':schema, '/api/sites/demo/components':[], '/api/sites/demo/pages/p1/studio-draft':{revision:0,blocks:[{id:'b1',type:'hero',title:'HESU AUTO',subtitle:'全球汽车出口',image:'',visible:true,style:{}},{id:'b2',type:'collection',title:'热门车型',visible:true,style:{}}],page_template:'standard',layout_mode:'append',entry:{title:'首页',route:'/'}}, }[path]; return {ok:!!data,status:data?200:404,headers:{get:()=> 'application/json'},json:async()=>data||{detail:'not available'},text:async()=>JSON.stringify(data)}; }; window.__previewOk=true; }''',schema) page.add_script_tag(content=js) page.evaluate('Studio.init()') page.wait_for_function("document.querySelector('#blockCount').textContent.includes('2')") assert page.locator('#tabStyle').is_hidden(),'Beginner mode should hide style tab' assert page.locator('#sfNextAction').inner_text() page.screenshot(path=str(OUT/'editor-desktop.png'),full_page=True) page.locator('#studioAdvancedButton').click() assert page.locator('#tabStyle').is_visible() page.locator('#tabStyle').click() assert page.locator('#tabStyle').get_attribute('aria-selected')=='true' page.locator('#studioAdvancedButton').click() assert page.locator('#tabStyle').is_hidden() assert page.locator('#tabContent').get_attribute('aria-selected')=='true' assert page.locator('.sf-photo-action button').count()==1 page.locator('#studioThemePreviewButton').click() page.wait_for_function("document.querySelector('#themePreviewStatus').textContent.includes('预览已显示')",timeout=5000) page.evaluate('window.__previewOk=false') page.locator('#themePreviewPage').select_option('product') page.wait_for_function("document.querySelector('#themePreviewRetry').hidden===false",timeout=5000) assert '503' in page.locator('#themePreviewStatus').inner_text() page.locator('button[onclick="Studio.closeThemePreview()"]').click() page.set_viewport_size({'width':390,'height':844}) page.wait_for_timeout(350) # allow the responsive drawers' CSS transition to finish page.screenshot(path=str(OUT/'editor-mobile.png'),full_page=True) overflow=page.evaluate('document.documentElement.scrollWidth>innerWidth+1') assert not overflow, 'Mobile horizontal overflow' page.locator('button[onclick="Studio.togglePane(\'right\')"]').click() assert page.locator('body').evaluate("x=>x.classList.contains('show-inspector')") page.locator('#sfCloseInspector').click() assert not page.locator('body').evaluate("x=>x.classList.contains('show-inspector')") assert not errors,errors browser.close() print(json.dumps({'browser':'isolated chromium','desktop':True,'mobile390':True,'preview_error_recovery':True,'advanced_mode':True,'js_errors':errors},ensure_ascii=False))