-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: move cursor relative to the center of body when using "resetCurs…
…or" option
- Loading branch information
Showing
5 changed files
with
131 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,4 +9,5 @@ module.exports = [ | |
"scrollIntoView", | ||
"openAndWait", | ||
"switchToRepl", | ||
"moveCursorTo", | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import type { Browser } from "../types"; | ||
|
||
type MoveToOptions = { | ||
xOffset?: number; | ||
yOffset?: number; | ||
}; | ||
|
||
// TODO: remove after next major version | ||
export = async (browser: Browser): Promise<void> => { | ||
const { publicAPI: session } = browser; | ||
|
||
session.addCommand( | ||
"moveCursorTo", | ||
async function (this: WebdriverIO.Element, { xOffset = 0, yOffset = 0 }: MoveToOptions = {}): Promise<void> { | ||
if (!this.isW3C) { | ||
return this.moveToElement(this.elementId, xOffset, yOffset); | ||
} | ||
|
||
const { x, y, width, height } = await this.getElementRect(this.elementId); | ||
const { scrollX, scrollY } = await session.execute(function (this: Window) { | ||
return { scrollX: this.scrollX, scrollY: this.scrollY }; | ||
}); | ||
|
||
const newXOffset = Math.floor(x - scrollX + (typeof xOffset === "number" ? xOffset : width / 2)); | ||
const newYOffset = Math.floor(y - scrollY + (typeof yOffset === "number" ? yOffset : height / 2)); | ||
|
||
return session | ||
.action("pointer", { parameters: { pointerType: "mouse" } }) | ||
.move({ x: newXOffset, y: newYOffset }) | ||
.perform(); | ||
}, | ||
true, | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters