File size: 1,728 Bytes
ef987bb | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | const path = require('path');
const { pathToFileURL } = require('url');
const { chromium } = require('playwright');
(async () => {
const browser = await chromium.launch({ headless: true });
const page = await browser.newPage({ viewport: { width: 900, height: 700 } });
await page.route(/^https?:\/\//, route => route.abort('blockedbyclient'));
await page.goto(pathToFileURL(path.join(process.cwd(), 'index.html')).href, { waitUntil: 'domcontentloaded' });
await page.locator('[data-testid="write-trigger"]').click();
const prompt = page.locator('[data-testid="prompt-input"]');
await prompt.fill('first question');
await page.locator('[data-testid="send-button"]').click();
await page.waitForTimeout(150);
const followup = page.locator('[data-testid="followup-input"]');
if (!(await followup.isVisible())) throw new Error('follow-up input should be created after first send');
const focusedId = await page.evaluate(() => document.activeElement && document.activeElement.getAttribute('data-testid'));
if (focusedId !== 'followup-input') throw new Error(`follow-up input should autofocus, focused=${focusedId}`);
await page.keyboard.type('second question');
const value = await followup.inputValue();
if (value !== 'second question') throw new Error('typing should go directly into focused follow-up input');
await page.keyboard.press('Enter');
await page.waitForTimeout(100);
const submitted = (await page.evaluate(()=>window.__getSubmissions())).at(-1);
if (submitted !== 'second question') {
throw new Error('Enter should submit or record the focused follow-up question');
}
await browser.close();
})().catch(err => { console.error(err && err.stack || err); process.exit(1); });
|