29 lines
1.5 KiB
JavaScript
29 lines
1.5 KiB
JavaScript
|
|
// Runs a simulated walk with voice on, with a stubbed speechSynthesis that records every utterance.
|
||
|
|
import { chromium } from 'playwright-core';
|
||
|
|
const browser = await chromium.launch();
|
||
|
|
const page = await browser.newPage({ viewport: { width: 1280, height: 850 }, locale: 'pl-PL' });
|
||
|
|
await page.addInitScript(() => {
|
||
|
|
window.__said = [];
|
||
|
|
let busy = false;
|
||
|
|
Object.defineProperty(window, 'speechSynthesis', { configurable: true, value: {
|
||
|
|
speak(u) { window.__said.push({ t: Date.now(), text: u.text, overlapped: busy }); busy = true; setTimeout(() => { busy = false; u.onend && u.onend(); }, 1800); },
|
||
|
|
cancel() { busy = false; },
|
||
|
|
} });
|
||
|
|
});
|
||
|
|
await page.goto(process.env.URL ?? 'http://localhost:4173/', { waitUntil: 'networkidle' });
|
||
|
|
await page.click('text=Zaloguj jako Anna Kowalska');
|
||
|
|
await page.click('nav >> text=Trasa');
|
||
|
|
await page.click(process.env.PRESET ?? 'text=Sukiennice → Zamek Królewski na Wawelu');
|
||
|
|
await page.waitForSelector('text=Warianty trasy');
|
||
|
|
await page.click('label[for=variant-1]');
|
||
|
|
await page.click('button.usa-button:has-text("Prowadź")');
|
||
|
|
await page.selectOption('#guide-voice', 'all');
|
||
|
|
await page.click('button:has-text("Symulacja GPS")');
|
||
|
|
const secs = Number(process.env.SECS ?? 100);
|
||
|
|
await page.waitForTimeout(secs * 1000);
|
||
|
|
const said = await page.evaluate(() => window.__said);
|
||
|
|
const t0 = said[0]?.t ?? 0;
|
||
|
|
console.log(`${said.length} utterances in ${secs}s`);
|
||
|
|
for (const s of said) console.log(` +${Math.round((s.t - t0) / 1000)}s ${s.overlapped ? '[OVERLAP] ' : ''}${s.text}`);
|
||
|
|
await browser.close();
|