Skip to content

Commit

Permalink
docs(extensibility): make selectors.register per worker (#26518)
Browse files Browse the repository at this point in the history
Fixes #26493
  • Loading branch information
mxschmitt authored Aug 17, 2023
1 parent adc9b2d commit 5bcd1fb
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions docs/src/extensibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => ({
Expand All @@ -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.
Expand Down

0 comments on commit 5bcd1fb

Please sign in to comment.