webdriverio
Version:
Next-gen browser and mobile automation test framework for Node.js
29 lines (28 loc) • 810 B
JavaScript
// src/scripts/isElementStable.ts
async function isElementStable(elem) {
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
};