From cea4e304b237aac608e50f7375d0d4984c8b680b Mon Sep 17 00:00:00 2001 From: shadowusr Date: Wed, 31 Jan 2024 16:29:34 +0300 Subject: [PATCH] fix: round xOffset and yOffset when resetting cursor --- src/worker/runner/test-runner/index.js | 3 ++- test/src/worker/runner/test-runner/index.js | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/worker/runner/test-runner/index.js b/src/worker/runner/test-runner/index.js index 67791e82c..6530c99d6 100644 --- a/src/worker/runner/test-runner/index.js +++ b/src/worker/runner/test-runner/index.js @@ -128,7 +128,8 @@ module.exports = class TestRunner { const { x = 0, y = 0 } = await session.execute(function () { return document.body.getBoundingClientRect(); }); - await body.moveTo({ xOffset: -x, yOffset: -y }); + // x and y must be integer, wdio will throw error otherwise + await body.moveTo({ xOffset: -Math.floor(x), yOffset: -Math.floor(y) }); } }; diff --git a/test/src/worker/runner/test-runner/index.js b/test/src/worker/runner/test-runner/index.js index c008ade09..f6c835a66 100644 --- a/test/src/worker/runner/test-runner/index.js +++ b/test/src/worker/runner/test-runner/index.js @@ -328,6 +328,14 @@ describe("worker/runner/test-runner", () => { assert.callOrder(body.scrollIntoView, body.moveTo); }); + + it("should floor coords if body element has fractional coords", async () => { + browser.publicAPI.execute.resolves({ x: 10.123, y: 15.899 }); + + await run_(); + + assert.calledOnceWith(body.moveTo, { xOffset: -10, yOffset: -15 }); + }); }); });