mirror of
https://github.com/microsoft/playwright.git
synced 2024-12-14 05:37:20 +03:00
docs(extensibility): make selectors.register per worker (#26518)
Fixes https://github.com/microsoft/playwright/issues/26493
This commit is contained in:
parent
adc9b2d390
commit
5bcd1fb65f
@ -26,8 +26,11 @@ Selectors must be registered before creating the page.
|
||||
|
||||
An example of registering selector engine that queries elements based on a tag name:
|
||||
|
||||
```js
|
||||
import { test, expect } from '@playwright/test';
|
||||
|
||||
```js title="baseTest.ts"
|
||||
import { test as base } from '@playwright/test';
|
||||
|
||||
export { expect } from '@playwright/test';
|
||||
|
||||
// Must be a function that evaluates to a selector engine instance.
|
||||
const createTagNameEngine = () => ({
|
||||
@ -42,11 +45,18 @@ const createTagNameEngine = () => ({
|
||||
}
|
||||
});
|
||||
|
||||
// Register selectors before any page is created.
|
||||
test.beforeAll(async ({ playwright }) => {
|
||||
// Register the engine. Selectors will be prefixed with "tag=".
|
||||
await playwright.selectors.register('tag', createTagNameEngine);
|
||||
export const test = base.extend<{}, { selectorRegistration: void }>({
|
||||
// Register selectors once per worker.
|
||||
selectorRegistration: [async ({ playwright }, use) => {
|
||||
// Register the engine. Selectors will be prefixed with "tag=".
|
||||
await playwright.selectors.register('tag', createTagNameEngine);
|
||||
await use();
|
||||
}, { scope: 'worker', auto: true }],
|
||||
});
|
||||
```
|
||||
|
||||
```js title="example.spec.ts"
|
||||
import { test, expect } from './baseTest';
|
||||
|
||||
test('selector engine test', async ({ page }) => {
|
||||
// Now we can use 'tag=' selectors.
|
||||
|
Loading…
Reference in New Issue
Block a user