module.exports = async function ({ browser, url: URL, out: OUT }) { const errors = []; const setups = [ ['desktop', { viewport: { width: 1280, height: 800 } }], ['phone-portrait', { viewport: { width: 390, height: 844 }, deviceScaleFactor: 2, isMobile: true, hasTouch: true }], ['phone-landscape', { viewport: { width: 844, height: 390 }, deviceScaleFactor: 2, isMobile: true, hasTouch: true }], ]; for (const [name, opts] of setups) { const ctx = await browser.newContext(opts); const page = await ctx.newPage(); page.on('console', m => { if (m.type() === 'error' || m.type() === 'warning') errors.push(`[${name}] console.${m.type()}: ${m.text()}`); }); page.on('pageerror', e => errors.push(`[${name}] pageerror: ${e.message}\n${e.stack}`)); await page.goto(URL); await page.waitForTimeout(600); await page.screenshot({ path: OUT + name + '-1-menu.png' }); await page.click('#btnSolo'); await page.waitForTimeout(400); await page.screenshot({ path: OUT + name + '-2-help.png' }); await page.click('#btnHelpClose'); await page.waitForTimeout(300); // build a bit const box = await page.locator('#board').boundingBox(); const cell = async (cx, cy) => { const r = await page.evaluate(([cx, cy]) => { const r = window.NW.app.renderer; const p = r.cellToScreen(cx, cy); return p; }, [cx, cy]); return { x: box.x + r.x, y: box.y + r.y }; }; await page.click('.tbtn[data-type="wall"]'); for (let y = 2; y <= 12; y++) { const p = await cell(12, y); await page.mouse.click(p.x, p.y); } await page.click('.tbtn[data-type="filter"]'); const isTouch = !!opts.hasTouch; for (const [cx, cy] of [[10, 12], [14, 12], [13, 9]]) { const p = await cell(cx, cy); if (isTouch) { await page.touchscreen.tap(p.x, p.y); await page.waitForTimeout(80); await page.touchscreen.tap(p.x, p.y); } else { await page.mouse.click(p.x, p.y); } await page.waitForTimeout(80); } await page.screenshot({ path: OUT + name + '-3-built.png' }); await page.click('#btnWave'); await page.waitForTimeout(4000); await page.screenshot({ path: OUT + name + '-4-wave.png' }); const st = await page.evaluate(() => { const v = window.NW.app.ctrl.view; return { gold: v.gold, lives: v.lives, wave: v.wave, towers: v.towers.length, monsters: v.monsters.length }; }); console.log(name, JSON.stringify(st)); await ctx.close(); } if (errors.length) throw new Error('console errors:\n' + errors.join('\n')); console.log('no console errors'); };