diff --git a/packages/isomorphic/locatorGenerators.ts b/packages/isomorphic/locatorGenerators.ts index 942c5d1c3ceb6..416b51a14cf0f 100644 --- a/packages/isomorphic/locatorGenerators.ts +++ b/packages/isomorphic/locatorGenerators.ts @@ -293,7 +293,7 @@ function combineTokens(factory: LocatorFactory, tokens: string[][], maxOutputSiz function detectExact(text: string): { exact?: boolean, text: string | RegExp } { let exact = false; - const match = text.match(/^\/(.*)\/([igm]*)$/); + const match = text.match(/^\/(.*)\/([dgimsuvy]*)$/); if (match) return { text: new RegExp(match[1], match[2]) }; if (text.endsWith('"')) { diff --git a/tests/library/locator-generator.spec.ts b/tests/library/locator-generator.spec.ts index cb3ad87158f96..175f4c8e0b110 100644 --- a/tests/library/locator-generator.spec.ts +++ b/tests/library/locator-generator.spec.ts @@ -113,6 +113,15 @@ it('reverse engineer locators', async ({ page }) => { javascript: 'getByLabel(/Last\\s+name/i)', python: 'get_by_label(re.compile(r"Last\\s+name", re.IGNORECASE))', }); + // Only JavaScript can express these flags, other languages drop them. + for (const flags of ['u', 's', 'y', 'd', 'v', 'gm']) { + for (const [engine, method] of [['text', 'getByText'], ['label', 'getByLabel']]) { + const selector = `internal:${engine}=/Hello/${flags}`; + const locatorString = asLocator('javascript', selector); + expect.soft(locatorString, selector).toBe(`${method}(/Hello/${flags})`); + expect.soft(parseLocator('javascript', locatorString, 'data-testid'), selector).toBe(selector); + } + } expect.soft(generate(page.getByPlaceholder('hello'))).toEqual({ csharp: 'GetByPlaceholder("hello")',