cmvr-visual/qa/browser-v3-final.cjs

11 lines
4.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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 live=JSON.parse(fs.readFileSync(path.join(root,'qa/v3-live.json'),'utf8'));
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('button',{name:'新建',exact:true}).click();
for(const section of await page.locator('.v2-shots>section').all())await section.locator('textarea').fill('界面音轨完整时长校验,不运行');
await page.getByRole('button',{name:'选择音频素材',exact:true}).click();await page.locator('.picker-item').filter({hasText:'鲲鹏完整旁白(开发验收).wav'}).click();await page.getByText('音频选段超过当前成片时长,请增加镜头或调整选段后再保存。',{exact:true}).waitFor();const audioEnd=()=>page.locator('label').filter({hasText:'源出点 ms'}).locator('input');if(Number(await audioEnd().inputValue())!==44425)throw new Error('Narration was silently truncated');let posts=0;page.on('request',r=>{if(r.url().endsWith('/api/workflows')&&r.method()==='POST')posts++});await page.getByRole('button',{name:'保存草稿',exact:true}).click();await page.getByText('音频选段与偏移必须在 360 帧内,不会自动截断长旁白',{exact:true}).waitFor();if(posts)throw new Error('Invalid overflow draft was submitted');
await page.locator('.v2-toolbar .el-select').first().click();await page.locator('.el-select-dropdown__item').filter({hasText:'鲲鹏·45秒旁白版(未运行)'}).click();await page.getByText('20 个镜头 · 1080 帧 · 45.00 秒',{exact:true}).waitFor();if(Number(await audioEnd().inputValue())!==44425)throw new Error('Saved full narration missing');await page.locator('.v2-page').evaluate(e=>e.scrollTop=0);await page.screenshot({path:path.join(root,'qa/v3-compact-desktop.png')});
const media=await page.evaluate(async id=>{const v=document.createElement('video');v.src='/api/assets/'+id+'/content';v.muted=true;v.preload='auto';document.body.append(v);await new Promise((resolve,reject)=>{v.addEventListener('loadedmetadata',resolve,{once:true});v.addEventListener('error',()=>reject(new Error('Video metadata error')),{once:true})});await v.play();await new Promise(resolve=>{v.addEventListener('seeked',resolve,{once:true});v.currentTime=15.5});v.pause();const result={duration:v.duration,width:v.videoWidth,height:v.videoHeight,seek:v.currentTime,error:v.error?.message||null};v.remove();return result},live.composition.asset_id);if(Math.abs(media.duration-16)>.05||Math.abs(media.seek-15.5)>.2||media.error)throw new Error('Long video playback failed');
await page.goto(base+'/help/kunpeng.html');await page.getByText('44.425秒',{exact:false}).first().waitFor();const href=await page.getByRole('link',{name:'下载45秒分镜',exact:true}).getAttribute('href');const example=await(await page.request.get(base+href)).json();if(example.render.total_frames!==1080||example.shots.length!==20)throw new Error('Compact download');await page.screenshot({path:path.join(root,'qa/v3-guide-desktop.png')});
const report={full_audio_ms:44425,overflow_blocked_before_http:posts===0,compact_draft_id:live.compact_draft_id,compact_frames:1080,compact_download:true,media,errors};fs.writeFileSync(path.join(root,'qa/v3-browser-final.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});