|
- const fs = require('node:fs');
- const path = require('node:path');
- const { pathToFileURL } = require('node:url');
- const { chromium } = require('@playwright/test');
- (async()=>{
- const dir=path.resolve(__dirname,'../reports/bridge-005-moss-junhao-v2-20260919');
- const browser=await chromium.launch({headless:true,channel:'chrome'});
- try {
- const page=await browser.newPage({viewport:{width:1280,height:1000}});
- await page.goto(pathToFileURL(path.join(dir,'index.html')).href);
- if(await page.locator('video').count()!==10) throw new Error('Expected five pairs of videos');
- const results=[];
- for(let step=0;step<5;step++){
- const video=page.locator('video').nth(step*2);
- await video.scrollIntoViewIfNeeded();
- await video.evaluate(v=>v.play());
- await page.waitForFunction(index=>{const v=document.querySelectorAll('video')[index];return v.currentTime>.15&&!v.paused&&!v.error},step*2);
- results.push(await video.evaluate(v=>({width:v.videoWidth,height:v.videoHeight,duration:v.duration,playing:!v.paused,error:v.error?.code||null})));
- await video.evaluate(v=>v.pause());
- }
- await page.evaluate(()=>scrollTo(0,0));
- await page.screenshot({path:path.join(dir,'preview-page.png')});
- fs.writeFileSync(path.join(dir,'playback-validation.json'),JSON.stringify(results,null,2));
- console.log('PASS: five new videos played, five original comparisons present',results);
- } finally {await browser.close()}
- })().catch(e=>{console.error(e.message);process.exitCode=1});
|