This repository was archived by the owner on Aug 6, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
✨ New locator based fixtures (4.4.0-beta.6) #431
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43a2716
to
bd7fb5c
Compare
Uggggh, Semantic Release got out of sync somehow and it's trying to release an already released version 😩 |
c01975d
to
05021a7
Compare
…ries This will likely replace the fixtures that provided `ElementHandle`-based queries in a future major release, but for now the `Locator` queries are exported as `locatorFixtures`: ```ts import { test as baseTest } from '@playwright/test' import { locatorFixtures as fixtures, LocatorFixtures as TestingLibraryFixtures, within } from '@playwright-testing-library/test/fixture'; const test = baseTest.extend<TestingLibraryFixtures>(fixtures); const {expect} = test; test('my form', async ({queries: {getByTestId}}) => { // Queries now return `Locator` const formLocator = getByTestId('my-form'); // Locator-based `within` support const {getByLabelText} = within(formLocator); const emailInputLocator = getByLabelText('Email'); // Interact via `Locator` API 🥳 await emailInputLocator.fill('email@playwright.dev'); // Assert via `Locator` APIs 🎉 await expect(emailInputLocator).toHaveValue('email@playwright.dev'); }) ```
### Global ```ts // playwright.config.ts import type { PlaywrightTestConfig } from '@playwright/test'; const config: PlaywrightTestConfig = { use: { testIdAttribute: 'data-custom-test-id', asyncUtilsTimeout: 5000, }, }; export default config; ``` ### Local ```ts import { test as baseTest } from '@playwright/test' import { locatorFixtures as fixtures, LocatorFixtures as TestingLibraryFixtures, within } from '@playwright-testing-library/test/fixture'; const test = baseTest.extend<TestingLibraryFixtures>(fixtures); const {expect} = test; // Entire test suite test.use({ testIdAttribute: 'data-custom-test-id' }); test.describe(() => { // Specific block test.use({ testIdAttribute: 'some-other-test-id', asyncUtilsTimeout: 5000, }); test('my form', async ({queries: {getByTestId}}) => { // ... }); }); ```
(until we have an official API for \`Locator\` queries that doesn't require a **@playwright/test** fixture)
This will likely replace the `queries` fixture when the `Locator` fixture stuff is officially released
Support `Page` in addition to `Locator` in `within()` fixture. When a `Page` instance is passed to `within()`, a `Screen` instance will be returned which includes the entire `Page` API in addition to the query methods. ```ts test('within page', async ({ page }) => { // Passing `page` to `within` returns a `Screen` instance const screen = within(page) await screen.goto(/* ... */) const form = screen.queryByRole('form', {name: 'User'}) // Passing a `Locator` returns scoped queries const {queryByLabelText} = within(form) // ... }) ```
🎉 This PR is included in version 4.4.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
New fixture for @playwright/test that is based on, and built with, more modern Playwright APIs. Queries return
Locator
instead ofElementHandle
and configuration is integrated into @playwright/test's configuration (global andtest.use
.Internally, @testing-library/dom is integrated via a custom selector engine. The integration is loaded via a [worker fixture]https://playwright.dev/docs/test-fixtures#worker-scoped-fixtures), ensuring everything works well with @playwright/test's parallelism.
This API will replace the legacy
ElementHandle
-based APIs in the next major release. However, before that happens, we will also make it compatible with vanilla playwright (without @playwright/test).This is comprised of the following pull requests, which were released as 4.x-beta.n: