Why the heck isn't there an equivalent to Playwright's locator? #31957
Replies: 3 comments
-
Storybook uses Testing Library DOM because it's executable in every browser, not just Playwright's special browser. You can read about why TL doesn't support CSS queries here. https://testing-library.com/docs/dom-testing-library/intro/ We are considering adding the locator API though. Request noted! |
Beta Was this translation helpful? Give feedback.
-
Some teams have actually managed to swap out Playwright for Play Functions when doing end-to-end testing, and it’s worked out pretty well for them. That said, one of the bigger headaches is the lack of built-in support for CSS selectors. To get around that, devs usually fall back on XPath or other tricks-like targeting elements by data attributes or text content. This isn’t really a technical limitation, though-it’s more about how Play Functions was designed. The idea is to keep things semantic and framework-agnostic, which can feel a bit limiting at first, but it pushes you toward writing tests that are cleaner and easier to maintain in the long run. Still, fingers crossed that future updates make life a little easier. |
Beta Was this translation helpful? Give feedback.
-
You can query elements using css selectors in Storybook by using
Although, as people mentioned above, relying on CSS selectors is fragile. Testing library has a great read on Query Priorities explaining it in more details. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm trying to use play functions for testing, but the lack of ability to search by css selector is very frustrating. In Playwright, I can do something like
page.locator("label[data-attribute='test']")
, and it would find the component without issue. Without this, there's no way to do serious testing. It's 2025, play functions are built on Playwright, there's no reason that this feature is omitted.Beta Was this translation helpful? Give feedback.
All reactions