28 lines
1.9 KiB
JavaScript
28 lines
1.9 KiB
JavaScript
// Capture the real extension renderer with the existing deterministic fixture.
|
|
// This never opens a personal browser profile or accesses real cookies.
|
|
import fs from "node:fs/promises";
|
|
import path from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
import { chromium } from "playwright";
|
|
const root = path.dirname(path.dirname(fileURLToPath(import.meta.url)));
|
|
const browser = await chromium.launch({ headless: true, executablePath: process.env.YTDL_TEST_BROWSER || "C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe" });
|
|
try {
|
|
const context = await browser.newContext({ viewport: { width: 520, height: 1080 }, reducedMotion: "reduce" });
|
|
await context.addInitScript({ path: path.join(root, "tests/ui-fixture.js") });
|
|
await context.route("**/*", async route => {
|
|
const url = new URL(route.request().url());
|
|
const name = path.basename(url.pathname);
|
|
if (url.hostname !== "ui.ytdl.test" || !["downloader.html", "downloader.js", "onboarding.js", "ui-connection.js", "theme-init.js", "styles.css", "shared.js", "session.js"].includes(name)) return route.abort();
|
|
return route.fulfill({ body: await fs.readFile(path.join(root,"extension",name)), contentType: name.endsWith(".html") ? "text/html" : name.endsWith(".css") ? "text/css" : "application/javascript" });
|
|
});
|
|
const page = await context.newPage();
|
|
await fs.mkdir(path.join(root,"site/assets"),{recursive:true});
|
|
for (const theme of ["dark","light"]) {
|
|
await page.goto(`https://ui.ytdl.test/downloader.html?url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DaircAruvnKk&theme=${theme}`);
|
|
await page.locator("#download-form").waitFor({state:"visible"});
|
|
await page.locator("#quality").selectOption("137");
|
|
await page.locator("#folder").fill("C:\\Videos");
|
|
await page.locator(".app").screenshot({path:path.join(root,`site/assets/menu-${theme}.png`),animations:"disabled"});
|
|
}
|
|
} finally { await browser.close(); }
|