Skip to content

Fix: wait for element to be stable fails on infinite animations (#2711)#2773

Open
NajoroRabiaza wants to merge 2 commits into
getgauge:masterfrom
NajoroRabiaza:fix-moving-links-2711
Open

Fix: wait for element to be stable fails on infinite animations (#2711)#2773
NajoroRabiaza wants to merge 2 commits into
getgauge:masterfrom
NajoroRabiaza:fix-moving-links-2711

Conversation

@NajoroRabiaza
Copy link
Copy Markdown
Contributor

Fixes #2711

This PR fixes an issue where actions like click() on elements with infinite CSS animations would not correctly wait for the 10-second timeout and would fail prematurely or proceed unpredictably.

Root Cause
The root cause was a combination of logic flaws in how element stability was checked and how timeouts were communicated back through the Chrome DevTools Protocol (CDP):

isInSamePosition was returning an integer instead of a boolean, confusing the stability logic.

A missing return statement after the initial requestAnimationFrame caused the comparison to happen immediately against the same object.

The 10-second timeout rejected with a primitive false instead of an Error object. In CDP, rejecting with a primitive value swallows the error (resulting in undefined), meaning the Node process never saw the timeout exception.

checkStable was not checking for res.exceptionDetails to propagate the error properly.

Changes Made
Updated isInSamePosition to return a strict boolean (topDiff + leftDiff + bottomDiff + rightDiff === 0).

Added the missing return; statement in waitForElementToBeStable after the first requestAnimationFrame call.

Modified the 10-second timeout to reject with a proper new Error("Element is not stable: still moving after 10000ms").

Added an exceptionDetails check inside checkStable to correctly intercept the timeout error from the browser context and throw it as a standard JavaScript Error in Node.js.

let elem = this;
return new Promise((resolve, reject) => {
setTimeout(() => reject(false), 10000);
setTimeout(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add an unit test covering this case ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I have add two unit tests, so one for when the element is stable and one for the infinite animation case

@NajoroRabiaza NajoroRabiaza force-pushed the fix-moving-links-2711 branch from 23dfe10 to 54067ed Compare April 24, 2026 09:45
…auge#2711)

Signed-off-by: NajoroRabiaza <hei.najoro.2@gmail.com>
Signed-off-by: NajoroRabiaza <hei.najoro.2@gmail.com>
@NajoroRabiaza NajoroRabiaza force-pushed the fix-moving-links-2711 branch from 54067ed to 7af6ab4 Compare April 24, 2026 12:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Click on Moving links is not waiting for the link to stop moving

2 participants