SPB Git
3.0 KB · 36 lines javascript
1import { chromium, devices } from "playwright";2import fs from "node:fs";3const BASE = process.env.BASE ?? "http://localhost:8500";4const PW = fs.readFileSync(process.env.PWFILE ?? (process.env.HOME + "/Desktop/Cluster/secrets/chat-spboucher-ai.devpassword"), "utf8").trim();5fs.mkdirSync("e2e-shots", { recursive: true });6const browser = await chromium.launch();7async function login(page) {8  await page.goto(BASE + "/login"); await page.fill('input[autocomplete="username"]', "simon"); await page.fill('input[type="password"]', PW); await page.click('button[type="submit"]'); await page.waitForURL(BASE + "/", { timeout: 20000 });9}10// desktop11const ctx = await browser.newContext({ viewport: { width: 1440, height: 900 }, deviceScaleFactor: 1 });12const page = await ctx.newPage(); const errors = []; page.on("pageerror", e => errors.push(e.message)); page.on("console", m => { if (m.type() === "error") errors.push(m.text()); });13await login(page);14await page.waitForSelector("textarea", { timeout: 20000 });15await page.screenshot({ path: "e2e-shots/01-home.png" });16// open model picker17await page.waitForTimeout(1500); await page.click('[data-testid="model-picker"]');18await page.waitForSelector("dialog[open]"); await page.screenshot({ path: "e2e-shots/02-model-picker.png" });19await page.locator('dialog[open] button', { hasText: "Claude Haiku 5.5" }).first().click().catch(async () => { await page.keyboard.press("Escape"); });20await page.fill("textarea", "Réponds en une phrase : quelle est la capitale du Québec ? Puis donne un tableau markdown de 2 lignes avec population approximative, et une formule LaTeX $E=mc^2$.");21await page.keyboard.press("Enter");22await page.waitForFunction(() => /\$/.test(document.body.innerText) && /→/.test(document.body.innerText), null, { timeout: 90000 }).catch(() => {});23await page.waitForTimeout(1500);24await page.screenshot({ path: "e2e-shots/03-answer.png", fullPage: false });25console.log("URL after send:", page.url());26// command palette27await page.keyboard.press("Meta+k"); await page.waitForSelector("dialog[open]"); await page.fill('dialog[open] input', "Québec"); await page.waitForTimeout(1200); await page.screenshot({ path: "e2e-shots/04-palette.png" }); await page.keyboard.press("Escape");28// mobile29console.log("desktop errors:", JSON.stringify(errors.slice(0, 10), null, 1));30const mctx = await browser.newContext({ ...devices["iPhone 15 Pro"] }); const mp = await mctx.newPage(); mp.on("pageerror", e => errors.push("mobile: " + e.message));31await login(mp); await mp.waitForSelector("textarea"); await mp.screenshot({ path: "e2e-shots/05-mobile-home.png" });32await mp.click('button[aria-label="Menu"]'); await mp.waitForTimeout(400); await mp.screenshot({ path: "e2e-shots/06-mobile-drawer.png" });33const convLink = mp.locator('aside:visible a[href^="/c/"]').first(); if (await convLink.count()) { await convLink.click(); await mp.waitForTimeout(1500); await mp.screenshot({ path: "e2e-shots/07-mobile-conv.png" }); }34console.log("page errors:", JSON.stringify(errors.slice(0, 10), null, 1));35await browser.close();36
Files · main
Menu

Theme