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
### 2a. Use _Playwright Test [fixture](https://playwright.dev/docs/test-fixtures)_
46
+
## 📝 Usage
47
+
48
+
There are currently a few different ways to use Playwright Testing Library, depending, however using the `Locator` queries fixture with Playwright Test (**@playwright/test**) is the recommended approach.
49
+
50
+
> ⚠️ The `ElementHandle` query APIs were created before Playwright introduced its `Locator` API and will be replaced in the next major version of Playwright Testing Library. If you can't use **@playwright/test** at the moment, you'll need to use the `ElementHandle` query API, but a migration path will be provided when we switch to the new `Locator` APIs.
51
+
52
+
### Playwright Test Fixture
53
+
54
+
Using the `Locator` Playwright Test (**@playwright/test**) fixture with **@playwright-testing-library/test**.
The `Locator` query API is configured using Playwright's `use` API. See Playwright's documentation for [global](https://playwright.dev/docs/api/class-testconfig#test-config-use), [project](https://playwright.dev/docs/api/class-testproject#test-project-use), and [test](https://playwright.dev/docs/api/class-test#test-use).
51
94
52
-
// As only fixture
53
-
const test =baseTest.extend<TestingLibraryFixtures>(fixtures)
95
+
##### Global
54
96
55
-
// Alternatively, with other fixtures
56
-
interfaceFixturesextendsTestingLibraryFixtures {
57
-
// ... additional fixture types
97
+
Configuring Testing Library globally in `playwright.config.ts`
> ⚠️ See note in [Usage](#-usage) as you should be using **@playwright/test** with the `Locator` fixture if possible. The `Locator` queries will be made available for standalone **playwright** in the next major release.
88
217
89
-
const {getByTestId, getByLabelText} = queries
218
+
```ts
219
+
import {beforeAll, expect, jest, test} from'@jest/globals'
220
+
import {webkit} from'playwright'// or 'firefox' or 'chromium'
All queries from **[@testing-library/dom](https://github.com/testing-library/dom-testing-library#usage)** are supported.
281
+
282
+
> 📝 The **`find*`** queries for the `Locator` queries return `Promise<Locator>` which resolves when the element is found before the timeout specified via `asyncUtilTimeout`
283
+
284
+
### Additional
285
+
111
286
Unique methods, not part of **@testing-library/dom**
112
287
288
+
> ⚠️ These only apply to the `ElementHandle` queries
289
+
113
290
- Get an `ElementHandle` for the document
114
291
115
292
```ts
@@ -126,72 +303,23 @@ Unique methods, not part of **@testing-library/dom**
126
303
): Promise<{}>
127
304
```
128
305
129
-
---
130
-
131
-
The **[@testing-library/dom](https://github.com/testing-library/dom-testing-library#usage)** — All **`get*`**, **`query*`**, and **`find*`** methods are supported.
132
-
133
-
-`getQueriesForElement(handle: ElementHandle): ElementHandle & QueryUtils` - extend the input object with the query API and return it
134
-
-`getNodeText(handle: ElementHandle): Promise<string>` - get the text content of the element
135
-
-`queries: QueryUtils` - the query subset of `@testing-library/dom` exports
136
-
-`queryByPlaceholderText`
137
-
-`queryAllByPlaceholderText`
138
-
-`getByPlaceholderText`
139
-
-`getAllByPlaceholderText`
140
-
-`findByPlaceholderText`
141
-
-`findAllByPlaceholderText`
142
-
-`queryByText`
143
-
-`queryAllByText`
144
-
-`getByText`
145
-
-`getAllByText`
146
-
-`findByText`
147
-
-`findAllByText`
148
-
-`queryByLabelText`
149
-
-`queryAllByLabelText`
150
-
-`getByLabelText`
151
-
-`getAllByLabelText`
152
-
-`findByLabelText`
153
-
-`findAllByLabelText`
154
-
-`queryByAltText`
155
-
-`queryAllByAltText`
156
-
-`getByAltText`
157
-
-`getAllByAltText`
158
-
-`findByAltText`
159
-
-`findAllByAltText`
160
-
-`queryByTestId`
161
-
-`queryAllByTestId`
162
-
-`getByTestId`
163
-
-`getAllByTestId`
164
-
-`findByTestId`
165
-
-`findAllByTestId`
166
-
-`queryByTitle`
167
-
-`queryAllByTitle`
168
-
-`getByTitle`
169
-
-`getAllByTitle`
170
-
-`findByTitle`
171
-
-`findAllByTitle`
172
-
-`queryByDisplayValue`,
173
-
-`queryAllByDisplayValue`,
174
-
-`getByDisplayValue`,
175
-
-`getAllByDisplayValue`,
176
-
-`findByDisplayValue`,
177
-
-`findAllByDisplayValue`,
178
-
179
306
## Known Limitations
180
307
181
-
- Async utilities `waitForElement`, `waitForElementToBeRemoved` and `waitForDomChange` are not exposed. Consider using a `find*` query.
182
-
-`fireEvent` method is not exposed, use Playwright's built-ins instead.
183
-
-`expect` assertion extensions are not available.
308
+
- Only `testIdAttribute` and `asyncUtilTimeout` are supported as configuration options
309
+
- Async utilities `waitForElement`, `waitForElementToBeRemoved` and `waitForDomChange` are not exposed. Consider using a `find*` query or a Playwright built-in like [`Locator.waitFor()`](https://playwright.dev/docs/api/class-locator#locator-wait-for).
310
+
- The `fireEvent` method is not exposed, use Playwright's built-ins instead.
311
+
- Assertion extensions from [**jest-dom**](https://testing-library.com/docs/ecosystem-jest-dom/) are not compatible, use Playwright Test if possible.
312
+
- The [`getNodeText()`](https://testing-library.com/docs/dom-testing-library/api-custom-queries/#getnodetext) function is not currently supported for `Locator`.
0 commit comments