| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- // 游戏流程截图脚本(tests/ui-shots.cjs):用 playwright-core 驱动真实页面,输出到 tests/shots/
- const { chromium } = require('/opt/data/tmp/domtest/node_modules/playwright-core');
- const EXE = '/opt/hermes/.playwright/chromium_headless_shell-1243/chrome-headless-shell-linux64/chrome-headless-shell';
- const BASE = process.env.BASE || 'http://127.0.0.1:8801/index.html';
- const OUT = process.env.OUT || '/opt/data/git-repos/worldtree-escape/tests/shots';
- const fs = require('fs');
- fs.mkdirSync(OUT, { recursive: true });
- (async () => {
- const browser = await chromium.launch({ executablePath: EXE, args: ['--no-sandbox'] });
- const errors = [];
- const hook = (page) => { page.on('pageerror', (e) => errors.push('pageerror: ' + e.message)); page.on('console', (m) => { if (m.type() === 'error') errors.push('console: ' + m.text()); }); page.on('requestfailed', (r) => errors.push('requestfailed: ' + r.url())); };
- // ── 桌面端
- const page = await browser.newPage({ viewport: { width: 1440, height: 900 } });
- hook(page);
- await page.goto(BASE); await page.waitForTimeout(1000);
- await page.screenshot({ path: OUT + '/desktop-1-start.png' });
- await page.evaluate(() => { const s = window.__wt.s; s.essence = 3e4; s.playSec = 200; s.upgrades = { root: 14, canopy: 5 }; s.lives = { sprout: 22, firefly: 9 }; s.layer = 26; s.maxLayerRound = 26; window.__wt.renderAll(); });
- await page.waitForTimeout(800);
- await page.screenshot({ path: OUT + '/desktop-2-progress.png' });
- // 回溯
- await page.click('[data-act="rebirth"]'); await page.waitForTimeout(500);
- await page.screenshot({ path: OUT + '/desktop-3-first-rebirth.png' });
- await page.evaluate(() => document.querySelector('[data-mact="close"]')?.click());
- // 里世界战斗
- await page.evaluate(() => { const w = window.__wt; w.s.playSec = 100; w.startRift(); w.riftRun.budget = 12; w.riftPanelKey = null; w.renderRiftPanel(); });
- await page.waitForTimeout(300);
- await page.evaluate(() => document.querySelector('[data-r="auto"]').click()); await page.waitForTimeout(300);
- await page.evaluate(() => document.querySelector('[data-r="build"]').click()); await page.waitForTimeout(300);
- await page.evaluate(() => window.__wt.rollRift(5)); await page.waitForTimeout(400);
- await page.screenshot({ path: OUT + '/desktop-4-rift-fight.png' });
- await page.evaluate(() => window.__wt.abandonRift()); await page.waitForTimeout(500);
- await page.screenshot({ path: OUT + '/desktop-5-rift-result.png' });
- await page.evaluate(() => document.querySelector('[data-mact="close"]')?.click());
- // 危机 / 文明
- await page.evaluate(() => { window.__wt.s.crisis.next = 0.1; }); await page.waitForTimeout(700);
- await page.screenshot({ path: OUT + '/desktop-6-crisis.png' });
- await page.evaluate(() => document.querySelector('[data-mact="crisis"]')?.click());
- await page.evaluate(() => { window.__wt.s.nextCivSec = 0.1; }); await page.waitForTimeout(600);
- await page.screenshot({ path: OUT + '/desktop-7-civilization.png' });
- await page.evaluate(() => document.querySelector('[data-mact="civ"]')?.click());
- // 存档
- await page.click('.top-save'); await page.waitForTimeout(400);
- await page.screenshot({ path: OUT + '/desktop-8-save.png' });
- await page.evaluate(() => window.__wt.closeModal());
- // 后期(大数字 + 修士位面)
- await page.evaluate(() => { const s = window.__wt.s; s.layer = 812; s.maxLayerRound = 812; s.essence = 1e42; s.upgrades = { root: 160, canopy: 40 }; s.lives = { sprout: 300, firefly: 250, rootwalker: 120, arbor: 90 }; s.treeLv = 24; s.crystals = 1e9; s.rebirths = 88; s.chapterSeen = 5; s.escaped = true; s.escapeCount = 1; s.planes = [{ explore: 100 }, { explore: 100 }, { explore: 73 }, { explore: 12 }]; s.exploreSum = 285; s.currentPlane = 3; s.relics = ['seed', 'star', 'gear']; window.__wt.renderLeft(); window.__wt.renderRight(); window.__wt.renderAll(); });
- await page.waitForTimeout(900);
- await page.screenshot({ path: OUT + '/desktop-9-late.png' });
- // ── 手机端 375×667
- const ctx = await browser.newContext({ viewport: { width: 375, height: 667 }, isMobile: true, hasTouch: true, deviceScaleFactor: 2 });
- const mp = await ctx.newPage(); hook(mp);
- await mp.goto(BASE); await mp.waitForTimeout(900);
- await mp.screenshot({ path: OUT + '/mobile-1-growth.png' });
- const of1 = await mp.evaluate(() => ({ sw: document.documentElement.scrollWidth, cw: document.documentElement.clientWidth }));
- await mp.click('#tabbar button[data-tab="center"]'); await mp.waitForTimeout(800);
- await mp.screenshot({ path: OUT + '/mobile-2-march.png' });
- await mp.click('#tabbar button[data-tab="right"]'); await mp.waitForTimeout(500);
- await mp.screenshot({ path: OUT + '/mobile-3-rebirth.png' });
- await mp.evaluate(() => { const w = window.__wt; w.s.playSec = 100; w.s.riftCdSec = 0; w.startRift(); w.riftRun.budget = 12; w.riftPanelKey = null; w.renderRiftPanel(); });
- await mp.waitForTimeout(400); await mp.screenshot({ path: OUT + '/mobile-4-rift-build.png' });
- await mp.evaluate(() => document.querySelector('[data-r="auto"]').click()); await mp.waitForTimeout(200);
- await mp.evaluate(() => document.querySelector('[data-r="build"]').click()); await mp.waitForTimeout(500);
- await mp.screenshot({ path: OUT + '/mobile-5-rift-fight.png' });
- const of2 = await mp.evaluate(() => ({ sw: document.documentElement.scrollWidth, cw: document.documentElement.clientWidth }));
- // 手机端点击升级
- const before0 = await mp.evaluate(() => [window.__wt.s.upgrades.root, window.__wt.s.essence, window.__wt.riftRun && window.__wt.riftRun.state]);
- await mp.evaluate(() => { const a = window.__wt; a.riftRun.state = 'result'; a.finishRift(); });
- await mp.waitForTimeout(400);
- await mp.screenshot({ path: OUT + '/mobile-6-rift-result.png' });
- await mp.evaluate(() => document.querySelector('[data-mact="close"]')?.click());
- await mp.evaluate(() => { window.__wt.s.riftCdSec = 0; window.__wt.s.essence = 1000; window.__wt.s.playSec = 200; window.__wt.renderAll(); });
- await mp.waitForTimeout(300);
- await mp.evaluate(() => window.__wt.showTab('left')); await mp.waitForTimeout(200);
- await mp.tap('#buy-root').catch(() => {});
- await mp.waitForTimeout(300);
- const after = await mp.evaluate(() => window.__wt.s.upgrades.root);
- console.log('mobile tap upgrade: before', JSON.stringify(before0), '→', after);
- console.log('overflow', JSON.stringify({ desktop: 'ok', mobile: of1, mobileRift: of2 }));
- console.log('errors', JSON.stringify(errors.slice(0, 10)));
- await browser.close();
- })();
|