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 `locator.waitForTransition()`

See original GitHub issue

I’d like to test computedStyles and visibility after some CSS transition (triggered by user input) finishes. From https://github.com/microsoft/playwright/issues/4055, it seems this is a common but unsupported use case.

const dropdown = await page.locator('.dropdown').

closeDropdown()
await dropdown.waitForTransition() // waitForElementState('stable') doesn't work if the element stays in place

expect(dropdown).toBeHidden()

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:18
  • Comments:16 (3 by maintainers)

github_iconTop GitHub Comments

9reactions
yury-scommented, Jul 14, 2022

You can probably use getAnimations and check if all/some of the animations have finished. Something like this:

const dropdown = await page.locator('.dropdown').

closeDropdown()
await dropdown.evaluate(e => Promise.all(e.getAnimations({ subtree: true }).map(animation => animation.finished)));

expect(dropdown).toBeHidden()

Will that work for you?

6reactions
janoshcommented, Aug 9, 2022

Wonderful, that does exactly what I need!

I use it in several places so wrapped it in a waitForAnimationEnd helper function:

import type { Page } from '@playwright/test'

function waitForAnimationEnd(page: Page, selector: string) {
  return page
    .locator(selector)
    .evaluate((element) =>
      Promise.all(
        element
          .getAnimations()
          .map((animation) => animation.finished)
      )
    )
}


test(`dropdown is hidden when reaching maxSelect items`, async ({ page }) => {
  await wait_for_animation_end(page, `div.dropdown`)

  expect(await page.locator(`div.dropdown`)).toBeHidden()
  expect(await page.getAttribute(`div.dropdown`, `class`)).toContain(`hidden`)
})

Would it make sense to have a waitForAnimationEnd method in @playwright/test?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Create a feature locator—ArcGIS Pro | Documentation
You can use this tool to build a locator to search names and unique attributes of your features, such as water meters; short...
Read more >
Wait for transition to end in puppeteer - Stack Overflow
I think I need to wait on the transitionend event, but I'm unsure of how to do that in Puppeteer. Any help would...
Read more >
Options - Splide
Determines whether to add the is-active class to clones. focus. Determines which slide should be active if there are multiple slides in a...
Read more >
Swiper API
If true , then active slide will be centered without adding gaps at the ... If disabled, then you need to init it...
Read more >
webdriverio/webdriverio - Gitter
@benzaremean I'm trying to achieve a wait for transition command with waitForTransition :) I don't love the idea of just using browser.pause() when...
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