gallery.ts
// Opening a gallery entry: park the hash, force a fresh document, wait for readiness.
// This is the setup etiquette every gallery scenario shared as a long-lived-browser
// convention; here it is explicit and self-contained per scenario.
import type { ScenarioContext } from "yukey-testkit/checks";
import { sleep } from "yukey-testkit/sleep";
export async function openGallery(
ctx: ScenarioContext,
hash: string,
readyExpr: string,
): Promise<void> {
const { cdp } = ctx;
// A fresh browser starts on about:blank: get onto gallery.html first.
// (Hash changes on the current document are synchronous; cross-document
// navigation needs the load wait before the reload below can be aimed.)
const onGallery = await cdp.js("location.pathname === '/gallery.html'");
if (onGallery !== true) {
await cdp.cmd("Page.navigate", { url: `${ctx.baseUrl}/gallery.html${hash}` });
for (let i = 0; i < 50; i++) {
if ((await cdp.js("document.readyState === 'complete'")) === true) break;
await sleep(100);
}
}
await cdp.js(`location.hash = ${JSON.stringify(hash)}`);
await cdp.cmd("Page.reload", { ignoreCache: true });
for (let i = 0; i < 50; i++) {
if ((await cdp.js(readyExpr)) === true) return;
await sleep(100);
}
throw new Error(`gallery entry ${hash} never became ready`);
}
packages/e2e/gallery.ts · 1.3 KiB · e5e792966c