Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/playwright-core/src/client/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ export class Selectors implements api.Selectors {
}

async register(name: string, script: string | (() => SelectorEngine) | { path?: string, content?: string }, options: { contentScript?: boolean } = {}): Promise<void> {
if (this._selectorEngines.some(engine => engine.name === name))
throw new Error(`selectors.register: "${name}" selector engine has been already registered`);

const source = await evaluationScript(this._platform, script, undefined, false);
const selectorEngine: channels.SelectorEngine = { ...options, name, source };
for (const context of this._contextsForSelectors)
Expand Down
5 changes: 5 additions & 0 deletions tests/library/selectors-register.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ it('should handle errors', async ({ playwright, browser }) => {
await page.close();
});

it('should throw "already registered" error when registering', { annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright/issues/36467' } }, async ({ playwright }) => {
await playwright.selectors.register('foo', createTagSelector);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a unique name, e.g. alreadyRegistered, otherwise this will conflict with other some other test.

await expect(playwright.selectors.register('foo', createTagSelector)).rejects.toThrowError('selectors.register: "foo" selector engine has been already registered');
});

it('should not rely on engines working from the root', async ({ playwright, browser }) => {
const page = await browser.newPage();
const createValueEngine = () => ({
Expand Down
Loading