33 lines
2.7 KiB
JavaScript
33 lines
2.7 KiB
JavaScript
// Capture real full-layout Razor pages. Screenshots require human/agent visual inspection;
|
|
// overflow metrics alone are not visual acceptance.
|
|
const { chromium } = require('playwright');
|
|
const fs = require('node:fs');
|
|
const path = require('node:path');
|
|
const output = process.env.PD_VISUAL_OUTPUT || '/srv/repos/plotdirector-phase2-artifacts/visual';
|
|
const stage = process.env.PD_VISUAL_STAGE || 'before';
|
|
const pages = process.env.PD_VISUAL_PAGES ? JSON.parse(process.env.PD_VISUAL_PAGES) : {writer:'page=writer'};
|
|
(async()=>{
|
|
fs.mkdirSync(output,{recursive:true}); const browser=await chromium.launch();const results=[];
|
|
try{for(const [name,query] of Object.entries(pages))for(const pwa of [false,true])for(const width of [1440,390])for(const theme of ['modern-light','modern-dark','warm-light','warm-dark']){
|
|
const context=await browser.newContext({viewport:{width,height:1000}});
|
|
if(pwa)await context.addInitScript(()=>Object.defineProperty(navigator,'standalone',{value:true}));
|
|
await context.route('**/signalr.min.js',route=>route.fulfill({contentType:'application/javascript',body:fs.readFileSync(require.resolve('@microsoft/signalr/dist/browser/signalr.min.js'))}));
|
|
const page=await context.newPage();const errors=[];page.on('pageerror',e=>errors.push(e.message));
|
|
const response=await page.goto('http://127.0.0.1:5238/fixture?'+query+'&layout=full');
|
|
await page.waitForTimeout(250);await page.evaluate(theme=>window.PlotDirectorApplyApplicationTheme(theme),theme);
|
|
await page.waitForTimeout(350); // Let the production theme transition settle before judging contrast.
|
|
if(process.env.PD_VISUAL_MAXIMISE==='1'){
|
|
await page.getByRole('button',{name:'Maximise workspace',exact:true}).click();
|
|
await page.waitForFunction(()=>!!document.querySelector('.pd-workspace-maximised'));
|
|
await page.waitForTimeout(350);
|
|
}
|
|
const file=`${stage}-${name}-${pwa?'pwa':'browser'}-${width}-${theme}.png`;
|
|
await page.screenshot({path:path.join(output,file),fullPage:true,animations:'disabled'});
|
|
const metrics=await page.evaluate(()=>({viewport:innerWidth,scroll:document.documentElement.scrollWidth,panels:[...document.querySelectorAll('.story-bible-section')].map(p=>({padding:getComputedStyle(p).padding, width:p.getBoundingClientRect().width}))}));
|
|
results.push({name,pwa,width,theme,file,status:response.status(),errors,metrics,visuallyInspected:false});
|
|
fs.writeFileSync(path.join(output,`${stage}-manifest.json`),JSON.stringify(results,null,2));await context.close();
|
|
}
|
|
fs.writeFileSync(path.join(output,`${stage}-manifest.json`),JSON.stringify(results,null,2));console.log(`${results.length} screenshots captured; inspection pending.`);
|
|
}finally{await browser.close();}
|
|
})().catch(e=>{console.error(e);process.exitCode=1;});
|