cmvr-visual/qa/browser-v2-layout.cjs

8 lines
2.9 KiB
JavaScript

const fs=require('fs'),path=require('path');const {chromium}=require('C:/Users/Administrator/.cache/codex-runtimes/codex-primary-runtime/dependencies/node/node_modules/playwright');
const root=path.resolve(__dirname,'..'),base='http://127.0.0.1:8000';
const env=Object.fromEntries(fs.readFileSync(path.join(root,'.env.server'),'utf8').split(/\r?\n/).filter(x=>x&&!x.startsWith('#')).map(x=>{const i=x.indexOf('=');return[x.slice(0,i),x.slice(i+1)]}));
(async()=>{let browser;try{browser=await chromium.launch({headless:true,channel:'chrome'});const page=await browser.newPage({viewport:{width:1440,height:1000}}),errors=[];page.on('pageerror',e=>errors.push(e.message));await page.goto(base+'/login');await page.getByPlaceholder('输入你的账号').fill(env.ADMIN_USERNAME);await page.getByPlaceholder('输入密码',{exact:true}).fill(env.ADMIN_PASSWORD);await page.getByRole('button',{name:'进入工作空间'}).click();await page.waitForURL('**/create/image');await page.goto(base+'/workflow');await page.getByRole('heading',{name:'把三个瞬间,连成一个故事。'}).waitFor();
await page.locator('.v2-toolbar .el-select').first().click();await page.locator('.el-select-dropdown__item').filter({hasText:'V2验收-三分镜-20261110'}).click();await page.waitForFunction(()=>document.querySelectorAll('textarea')[0]?.value.includes('industrial inspection'));
await page.locator('.v2-page').evaluate(el=>el.scrollTop=0);await page.mouse.move(900,650);await page.mouse.wheel(0,1800);await page.waitForTimeout(250);const desktop=await page.locator('.v2-page').evaluate(el=>({top:el.scrollTop,height:el.clientHeight,total:el.scrollHeight}));if(desktop.top<1)throw new Error('Workflow cannot be scrolled with mouse wheel');await page.screenshot({path:path.join(root,'qa/v2-workflow-desktop-bottom.png'),fullPage:true});await page.locator('.v2-page').evaluate(el=>el.scrollTop=0);await page.screenshot({path:path.join(root,'qa/v2-workflow-desktop.png'),fullPage:true});
await page.setViewportSize({width:390,height:844});await page.locator('.v2-page').evaluate(el=>el.scrollTop=0);await page.screenshot({path:path.join(root,'qa/v2-workflow-mobile.png'),fullPage:true});await page.mouse.move(250,650);await page.mouse.wheel(0,8000);await page.waitForTimeout(250);const mobile=await page.locator('.v2-page').evaluate(el=>({top:el.scrollTop,height:el.clientHeight,total:el.scrollHeight,overflow:el.scrollWidth>el.clientWidth+2}));if(mobile.top<1||mobile.overflow||mobile.total-mobile.height-mobile.top>3)throw new Error('Mobile workflow settings cannot be reached');await page.screenshot({path:path.join(root,'qa/v2-workflow-mobile-bottom.png'),fullPage:true});const report={desktop,mobile,errors};fs.writeFileSync(path.join(root,'qa/v2-layout.json'),JSON.stringify(report,null,2));console.log(JSON.stringify(report));}finally{if(browser)await browser.close()}})().catch(e=>{console.error(e.message);process.exitCode=1});