mirror of
https://github.com/microsoft/playwright.git
synced 2024-12-14 21:53:35 +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:
|
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.
|
// Must be a function that evaluates to a selector engine instance.
|
||||||
const createTagNameEngine = () => ({
|
const createTagNameEngine = () => ({
|
||||||
@ -42,11 +45,18 @@ const createTagNameEngine = () => ({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Register selectors before any page is created.
|
export const test = base.extend<{}, { selectorRegistration: void }>({
|
||||||
test.beforeAll(async ({ playwright }) => {
|
// Register selectors once per worker.
|
||||||
// Register the engine. Selectors will be prefixed with "tag=".
|
selectorRegistration: [async ({ playwright }, use) => {
|
||||||
await playwright.selectors.register('tag', createTagNameEngine);
|
// 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 }) => {
|
test('selector engine test', async ({ page }) => {
|
||||||
// Now we can use 'tag=' selectors.
|
// Now we can use 'tag=' selectors.
|
||||||
|
Loading…
Reference in New Issue
Block a user