From 2abcdbe67dc0cff118789180d8d882687ad07a16 Mon Sep 17 00:00:00 2001 From: Simon Knott Date: Mon, 21 Oct 2024 17:18:27 +0200 Subject: [PATCH] support engine names --- .../src/utils/isomorphic/locatorGenerators.ts | 20 +++++++++++++++---- tests/library/locator-generator.spec.ts | 2 ++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/packages/playwright-core/src/utils/isomorphic/locatorGenerators.ts b/packages/playwright-core/src/utils/isomorphic/locatorGenerators.ts index ecc0d8f47f..431c30366b 100644 --- a/packages/playwright-core/src/utils/isomorphic/locatorGenerators.ts +++ b/packages/playwright-core/src/utils/isomorphic/locatorGenerators.ts @@ -197,13 +197,25 @@ function innerAsLocators(factory: LocatorFactory, parsed: ParsedSelector, isFram const locatorParts = [locatorPart, locatorPartWithEngine].filter(Boolean) as string[]; if (nextPart && nextPart.name === 'internal:control' && (nextPart.body as string) === 'enter-frame') { - // Two options: + // two options plus engine name: // - locator('iframe').contentFrame() + // - locator('css|xpath=iframe').contentFrame() // - frameLocator('iframe') - tokens.push([ - ...locatorParts.map(p => factory.chainLocators([p, factory.generateLocator(base, 'frame', '')])), + // - frameLocator('css|xpath=iframe') + + const contentFrame = factory.generateLocator(base, 'frame', '') + const options = [ + factory.chainLocators([locatorPart, contentFrame]), factory.generateLocator(base, 'frame-locator', selectorPart), - ]); + ] + + if (locatorPartWithEngine) + options.push( + factory.chainLocators([locatorPartWithEngine, contentFrame]), + factory.generateLocator(base, 'frame-locator', stringifySelector({ parts: [part] }, /* forceEngineName */ true)), + ) + + tokens.push(options); nextBase = 'frame-locator'; index++; continue; diff --git a/tests/library/locator-generator.spec.ts b/tests/library/locator-generator.spec.ts index 90125c7547..1b951b533f 100644 --- a/tests/library/locator-generator.spec.ts +++ b/tests/library/locator-generator.spec.ts @@ -588,7 +588,9 @@ it('parse locators strictly', () => { it('parseLocator frames', async () => { expect.soft(parseLocator('javascript', `locator('iframe').contentFrame().getByText('foo')`, '')).toBe(`iframe >> internal:control=enter-frame >> internal:text=\"foo\"i`); expect.soft(parseLocator('javascript', `frameLocator('iframe').getByText('foo')`, '')).toBe(`iframe >> internal:control=enter-frame >> internal:text=\"foo\"i`); + expect.soft(parseLocator('javascript', `frameLocator('css=iframe').getByText('foo')`, '')).toBe(`css=iframe >> internal:control=enter-frame >> internal:text=\"foo\"i`); expect.soft(parseLocator('python', `locator("iframe").content_frame.get_by_text("foo")`, '')).toBe(`iframe >> internal:control=enter-frame >> internal:text=\"foo\"i`); expect.soft(parseLocator('python', `frame_locator("iframe").get_by_text("foo")`, '')).toBe(`iframe >> internal:control=enter-frame >> internal:text=\"foo\"i`); + expect.soft(parseLocator('python', `frame_locator("css=iframe").get_by_text("foo")`, '')).toBe(`css=iframe >> internal:control=enter-frame >> internal:text=\"foo\"i`); });