You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: api/browser/locators.md
+23Lines changed: 23 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,6 +13,29 @@ The locator API uses a fork of [Playwright's locators](https://playwright.dev/do
13
13
This page covers API usage. To better understand locators and their usage, read [Playwright's "Locators" documentation](https://playwright.dev/docs/locators).
14
14
:::
15
15
16
+
::: tip Difference from `testing-library`
17
+
Vitest's `page.getBy*` methods return a locator object, not a DOM element. This makes locator queries composable and allows Vitest to retry interactions and assertions when needed.
18
+
19
+
Compared to testing-library queries:
20
+
21
+
- Use locator chaining (`.getBy*`, `.filter`, `.nth`) instead of `within(...)`.
22
+
- Keep locators around and interact with them later (`await locator.click()`), instead of resolving elements up front.
23
+
- Single-element escape hatches like `.element()` and `.query()` are strict and throw if multiple elements match.
0 commit comments