UNPKG

webdriverio

Version:

Next-gen browser and mobile automation test framework for Node.js

32 lines (31 loc) • 1.03 kB
// src/scripts/isElementStable.ts async function isElementStable(elem) { if (typeof elem.isConnected === "boolean" && !elem.isConnected || elem.ownerDocument && elem.ownerDocument !== document) { throw new Error("stale element reference: element is not attached to the page document"); } if (document.visibilityState === "hidden") { throw Error("You are checking for animations on an inactive tab, animations do not run for inactive tabs"); } try { const previousPosition = elem.getBoundingClientRect(); await new Promise((resolve) => { const timer = setTimeout(resolve, 100); requestAnimationFrame(() => requestAnimationFrame(() => { clearTimeout(timer); resolve(); })); }); const currentPosition = elem.getBoundingClientRect(); for (const prop in previousPosition) { if (previousPosition[prop] !== currentPosition[prop]) { return false; } } return true; } catch { return false; } } export { isElementStable as default };