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)});