PlotDirector/PlotLine.Tests/Browser/writer3-visual-capture.cjs

9 lines
2.2 KiB
JavaScript

// Read-only authenticated Development screenshots; requires a dedicated disposable identity.
const{chromium}=require('playwright'),fs=require('node:fs'),assert=require('node:assert/strict');
(async()=>{const w=JSON.parse(fs.readFileSync(process.env.PD_WRITER3_IDENTITY)),out=process.env.PD_WRITER3_SCREENSHOTS;assert(w.Database==='PlotDirector_Development'&&out&&w.Email.endsWith('@example.invalid'));fs.mkdirSync(out,{recursive:true});const b=await chromium.launch();try{const p=await b.newPage({viewport:{width:1440,height:1000}});await p.goto('https://dev.plotdirector.com/Account/Login');await p.locator('[name=Email]').fill(w.Email);await p.locator('[name=Password]').fill(w.Password);await Promise.all([p.waitForURL('**/Projects'),p.locator('button[type=submit]').click()]);const records=[];
for(const width of[1440,1024,390])for(const d of['Index','Write','Explore','Plan','Review','Reflect']){
await p.setViewportSize({width,height:width===390?844:900});await p.goto(`https://dev.plotdirector.com/Writer/${d}?projectId=${w.project}&bookId=${w.book}`);await p.evaluate(()=>window.PlotDirectorApplyApplicationTheme('modern-dark'));await p.evaluate(()=>{for(const k of Object.keys(localStorage).filter(k=>k.startsWith('plotdirector.writerLayout.')))localStorage.removeItem(k)});await p.reload();await p.evaluate(()=>window.PlotDirectorApplyApplicationTheme('modern-dark'));await p.evaluate(()=>new Promise(r=>requestAnimationFrame(()=>requestAnimationFrame(r))));await p.mouse.move(0,0);
await p.screenshot({path:`${out}/${d}-${width}.png`,fullPage:true,animations:"disabled"});records.push({destination:d,width,...await p.evaluate(()=>({overflowX:document.documentElement.scrollWidth-innerWidth,overflowY:document.documentElement.scrollHeight-innerHeight,heading:document.querySelector('.writer3 h1')?.textContent.trim()}))});
if(['Write','Explore'].includes(d)){const t=p.locator('.writer3-layout-tools button').first();await t.click();await p.mouse.move(0,0);await p.screenshot({path:`${out}/${d}-${width}-${await p.locator('.writer3-reference').isHidden()?'collapsed':'companion'}.png`,fullPage:true,animations:"disabled"});}
}console.log(JSON.stringify(records,null,2));}finally{await b.close()}})().catch(e=>{console.error(e.message);process.exitCode=1});