From e8a652a5a569e33f79f1b7f85025579cdcf98740 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Tue, 17 Nov 2026 15:13:43 +0000 Subject: [PATCH] test(e2e): add a real mouse drag step to the CDP and BiDi drivers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A step may carry drag [[x0, y0], [x1, y1]]: after its keys and before its probe the driver presses the left mouse button at the first viewport point, moves to the second and releases (Input.dispatchMouseEvent in cdp.mjs, input.performActions in bidi.mjs). Synthetic PointerEvents cannot take pointer capture, so steer() and swipe handlers need trusted input. Proven by the hub sky e2e (feature/orchestrator-cosmos), green in Chromium and Firefox at 1920/1366/390; the Match swipe e2e builds on it. 🎯 Fix: 93 % 💥 Break: 3 % 💸 Tokens: – ⏱️ Velocity: – 🛡️ Security: 100 % 🏆 Score: 90 🚦 Gate: ✅ 90/5, tokens and velocity <= 100, security 100 % Co-Authored-By: Claude Opus 5.5 --- tests/e2e/bidi.mjs | 10 ++++++++-- tests/e2e/cdp.mjs | 13 +++++++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/tests/e2e/bidi.mjs b/tests/e2e/bidi.mjs index 5b523a8..1b174a7 100644 --- a/tests/e2e/bidi.mjs +++ b/tests/e2e/bidi.mjs @@ -4,8 +4,8 @@ import {createServer} from "node:net"; import {tmpdir} from "node:os"; import {join} from "node:path"; -// Args: ; the plan lists steps {width, height, url, wait, keys, probe, shot, gesture} and an -// optional init like cdp.mjs. +// Args: ; the plan lists steps {width, height, url, wait, keys, drag, probe, shot, gesture} and +// an optional init like cdp.mjs. // Prints {results, errors}: one probe value per step and every JavaScript error the page logged. const [binary, planFile] = process.argv.slice(2); const plan = JSON.parse(readFileSync(planFile, "utf8")); @@ -86,6 +86,12 @@ try { await send("input.performActions", {context, actions: [{type: "key", id: "keyboard", actions: [{type: "keyDown", value: KEYS[key]}, {type: "keyUp", value: KEYS[key]}]}]}); await sleep(250); } + if (step.drag) { + const [[x0, y0], [x1, y1]] = step.drag; + const moves = [{type: "pointerMove", x: x0, y: y0}, {type: "pointerDown", button: 0}, {type: "pointerMove", x: x1, y: y1}, {type: "pointerUp", button: 0}]; + await send("input.performActions", {context, actions: [{type: "pointer", id: "mouse", parameters: {pointerType: "mouse"}, actions: moves}]}); + await sleep(250); + } let value = null; if (step.probe) { const answer = await send("script.evaluate", {expression: `(async () => JSON.stringify(await ${step.probe}))()`, target: {context}, awaitPromise: true, resultOwnership: "none", userActivation: Boolean(step.gesture)}); diff --git a/tests/e2e/cdp.mjs b/tests/e2e/cdp.mjs index 1eee960..72692ab 100644 --- a/tests/e2e/cdp.mjs +++ b/tests/e2e/cdp.mjs @@ -3,8 +3,9 @@ import {mkdtempSync, readFileSync, rmSync, writeFileSync} from "node:fs"; import {tmpdir} from "node:os"; import {join} from "node:path"; -// Args: ; the plan lists steps {width, height, url, wait, keys, probe, shot, media, gesture}, -// keys being real key presses (Enter, Tab, ArrowLeft, ArrowRight) on the focused element before the probe and gesture running the probe with a +// Args: ; the plan lists steps {width, height, url, wait, keys, drag, probe, shot, media, gesture}, +// keys being real key presses (Enter, Tab, ArrowLeft, ArrowRight) on the focused element before the probe, drag +// [[x, y], [x, y]] a real left mouse drag between two viewport points after the keys, and gesture running the probe with a // user activation like a click, an optional init, the text of a function every new document runs before its own scripts, // and an optional authenticator {credentialId, privateKey, rpId}: base64 id and PKCS#8 key of a passkey the page may sign with. // Prints {results, errors}: one probe value per step and every uncaught page exception. @@ -93,6 +94,14 @@ try { await page("Input.dispatchKeyEvent", {type: "keyUp", key, code: key, windowsVirtualKeyCode: code}); await sleep(250); } + if (step.drag) { + const [[x0, y0], [x1, y1]] = step.drag; + await page("Input.dispatchMouseEvent", {type: "mouseMoved", x: x0, y: y0}); + await page("Input.dispatchMouseEvent", {type: "mousePressed", x: x0, y: y0, button: "left", buttons: 1, clickCount: 1}); + await page("Input.dispatchMouseEvent", {type: "mouseMoved", x: x1, y: y1, button: "left", buttons: 1}); + await page("Input.dispatchMouseEvent", {type: "mouseReleased", x: x1, y: y1, button: "left", buttons: 0, clickCount: 1}); + await sleep(250); + } let value = null; if (step.probe) { const {result, exceptionDetails} = await page("Runtime.evaluate", {expression: step.probe, awaitPromise: true, returnByValue: true, userGesture: Boolean(step.gesture)});