webdriverio
Version:
Next-gen browser and mobile automation test framework for Node.js
43 lines (39 loc) • 948 B
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = moveTo;
var _utils = require("../../utils");
async function moveTo({
xOffset,
yOffset
} = {}) {
if (!this.isW3C) {
return this.moveToElement(this.elementId, xOffset, yOffset);
}
const {
x,
y,
width,
height
} = await (0, _utils.getElementRect)(this);
const {
scrollX,
scrollY
} = await (0, _utils.getScrollPosition)(this);
const newXOffset = parseInt(x - scrollX + (typeof xOffset === 'number' ? xOffset : width / 2), 10);
const newYOffset = parseInt(y - scrollY + (typeof yOffset === 'number' ? yOffset : height / 2), 10);
return this.performActions([{
type: 'pointer',
id: 'finger1',
parameters: {
pointerType: 'mouse'
},
actions: [{
type: 'pointerMove',
duration: 0,
x: newXOffset,
y: newYOffset
}]
}]).then(() => this.releaseActions());
}