question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Feature] Add waitForAnimation

See original GitHub issue

Perhaps I have misunderstood the existing API, but I’ve found it tricky to wait reliably for elements with animations (e.g. a fade-in using opacity).

I saw a solution to this problem using Puppeteer on Stack Overflow and successfully applied the same pattern in my Playwright tests (see code below).

export const waitForAnimation = async (frame, selector) => {
  return frame.$eval(selector, el => new Promise((res, _) => {
    const onEnd = () => {
      el.removeEventListener('animationend', onEnd)
      res()
    }
    el.addEventListener("animationend", onEnd)
  }))
}
// Usage
await waitForAnimation(frame, 'div >> "Look at this div's fade-in animation!"')

But ideally there could be an API resembling waitForSelector:

frame.waitForAnimation('div >> "Look at this div's fade-in animation!"')

ElementHandle.waitForElementState("stable") looked like it could work for this purpose, but on closer reading it sounds like this will only work for animations which affect the element’s bounding box (so not for opacity)

Again, pardon my ignorance if the API already handles animations/transitions with another method, but otherwise this seemed like a fairly common use case that is reliably solved with event listeners.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:32
  • Comments:15 (6 by maintainers)

github_iconTop GitHub Comments

20reactions
janoshcommented, Apr 7, 2022

@aslushnikov I think this issue should remain open for now. What about e2e testing? The OP was not concerned with screenshots it seems to me. In my case, I need to test computedStyles on an element after its transition following user input has finished.

9reactions
aslushnikovcommented, Feb 15, 2022

Everybody: the disableAnimations option has landed on @playwright/test@next for page.screenshot, locator.screenshot and elementHandle.screenshot. This should stop all the CSS animations and transitions; please give it a try!

Read more comments on GitHub >

github_iconTop Results From Across the Web

This function WaitForAnimation exist? - Unity Forum
I'm a little confusing if is WaitForAnimation right or WaitForSecond? I'm using this code to make the animation finish after complete.
Read more >
Window.requestAnimationFrame() - Web APIs | MDN
requestAnimationFrame() method tells the browser that you wish to perform an animation and requests that the browser calls a specified function ...
Read more >
Wait for animation function in javascript - jquery - Stack Overflow
show() overlays the current scene with a complete new markup and css. – polyte. Jul 5, 2013 at 16:50. Add a comment ...
Read more >
Configuration - Cypress Documentation
The defineConfig helper function is exported by Cypress, and it provides ... waitForAnimations, true, Whether to wait for elements to finish animating ...
Read more >
Wait for animation in every function in the call stack
Lets say I have a function func_20 that calls func_19, ... You usually first add the functionality and then start adding things to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found