Files
fishing-game/tests/debug.js
T

51 lines
1.8 KiB
JavaScript

const puppeteer = require('puppeteer-core');
const path = require('path');
const GAME_DIR = '/home/andrey/work/fishing-game';
const GAME = 'file://' + path.join(GAME_DIR, 'index.html');
const CHROMIUM = process.env.CHROMIUM || '/usr/bin/chromium-browser';
const sleep = ms => new Promise(r => setTimeout(r, ms));
(async () => {
const browser = await puppeteer.launch({
executablePath: CHROMIUM, headless: true,
args: ['--no-sandbox', '--disable-dev-shm-usage', '--mute-audio'],
});
const page = await browser.newPage();
await page.setViewport({ width: 1280, height: 720, deviceScaleFactor: 1 });
await page.goto(GAME, { waitUntil: 'load' });
await page.evaluate(() => localStorage.clear());
await page.reload({ waitUntil: 'load' });
await page.waitForFunction(() => !document.getElementById('menu').classList.contains('hidden'), { timeout: 8000, polling: 50 });
await page.click('#btnPlay');
await page.waitForFunction(() => state === 'IDLE', { timeout: 3000, polling: 50 });
await page.mouse.move(640, 360);
await page.mouse.down(); await sleep(650); await page.mouse.up();
await page.waitForFunction(() => state === 'WAIT', { timeout: 3000, polling: 50 });
await page.evaluate(() => { forceBite = true; biteTimer = 0.05; recall(); });
await sleep(100);
const debug = await page.evaluate(() => {
return {
state: state,
forceBite: forceBite,
biteTimer: biteTimer,
uiOpen: uiOpen,
recallExists: typeof recall === 'function',
};
});
console.log('After recall:', debug);
try {
await page.waitForFunction(() => state === 'BITE', { timeout: 3000, polling: 50 });
console.log('BITE reached!');
} catch (e) {
console.log('BITE timeout, state:', await page.evaluate(() => state));
}
await browser.close();
})();