diff --git a/src/browser/pw-tools-core.test.ts b/src/browser/pw-tools-core.test.ts index 965d41485..b60bee2e9 100644 --- a/src/browser/pw-tools-core.test.ts +++ b/src/browser/pw-tools-core.test.ts @@ -396,6 +396,22 @@ describe("pw-tools-core", () => { expect(res.truncated).toBe(true); }); + it("scrolls a ref into view (default timeout)", async () => { + const scrollIntoViewIfNeeded = vi.fn(async () => {}); + currentRefLocator = { scrollIntoViewIfNeeded }; + currentPage = {}; + + const mod = await importModule(); + await mod.scrollIntoViewViaPlaywright({ + cdpUrl: "http://127.0.0.1:18792", + targetId: "T1", + ref: "1", + }); + + expect(sessionMocks.refLocator).toHaveBeenCalledWith(currentPage, "1"); + expect(scrollIntoViewIfNeeded).toHaveBeenCalledWith({ timeout: 20_000 }); + }); + it("rewrites strict mode violations into snapshot hints", async () => { const click = vi.fn(async () => { throw new Error( diff --git a/src/browser/server.test.ts b/src/browser/server.test.ts index f406db7ba..9dd482d5a 100644 --- a/src/browser/server.test.ts +++ b/src/browser/server.test.ts @@ -34,6 +34,7 @@ const pwMocks = vi.hoisted(() => ({ fillFormViaPlaywright: vi.fn(async () => {}), getConsoleMessagesViaPlaywright: vi.fn(async () => []), hoverViaPlaywright: vi.fn(async () => {}), + scrollIntoViewViaPlaywright: vi.fn(async () => {}), navigateViaPlaywright: vi.fn(async () => ({ url: "https://example.com" })), pdfViaPlaywright: vi.fn(async () => ({ buffer: Buffer.from("pdf") })), pressKeyViaPlaywright: vi.fn(async () => {}), @@ -416,6 +417,18 @@ describe("browser control server", () => { ref: "2", }); + const scroll = (await realFetch(`${base}/act`, { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ kind: "scrollIntoView", ref: "2" }), + }).then((r) => r.json())) as { ok: boolean }; + expect(scroll.ok).toBe(true); + expect(pwMocks.scrollIntoViewViaPlaywright).toHaveBeenCalledWith({ + cdpUrl: cdpBaseUrl, + targetId: "abcd1234", + ref: "2", + }); + const drag = (await realFetch(`${base}/act`, { method: "POST", headers: { "Content-Type": "application/json" },