Skip to content

[Bug]: "selector engine has been already registered" error now occurs in when browser.newContext is called instead of when the selector is registered #36467

@DetachHead

Description

@DetachHead

Version

1.53.1

Steps to reproduce

test.beforeAll(async () => {
    await selectors.register('foo', () => {})
    await selectors.register('foo', () => {}) // used to fail here
})

test('asdf', async ({ page }) => { // now fails here
    await page.isVisible('asdf')
})

Expected behavior

error occurs on the second await selectors.register('foo', () => {})

Actual behavior

error occurs when the browser context is opened

Additional context

our tests register a few known selector engines dynamically, but they don't have a way to tell if one has already been registered, so i wrote a function for registering selector engines that suppresses the error if it's already been registered:

const registerSelectorEngine = async (
    name: string,
    script: Parameters<typeof selectors.register>[1],
) => {
    try {
        await selectors.register(name, script)
    } catch {
        console.log(`selector engine ${name} was already registered`)
    }
}

this worked on previous versions of playwright, but as of 1.53 it no longer catches the error.

i tried on 1.52 as well and the error does not seem to be thrown at all, so i'm not sure what the last version of playwright was where this function actually worked as i expected.

Environment

System:
    OS: Windows 11 10.0.22631
    CPU: (12) x64 11th Gen Intel(R) Core(TM) i5-11500H @ 2.90GHz
    Memory: 5.62 GB / 31.20 GB
  Binaries:
    Node: 19.7.0 - ~\AppData\Roaming\node\node.EXE
    npm: 9.5.0 - ~\AppData\Roaming\node\npm.CMD
  IDEs:
    VSCode: 1.101.1 - C:\Users\user\AppData\Local\Programs\Microsoft VS Code\bin\code.CMD
  npmPackages:
    @playwright/test: 1.53.1 => 1.53.1 
    playwright: ^1.43.0 => 1.53.1

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions