support engine names

This commit is contained in:
Simon Knott 2024-10-21 17:18:27 +02:00
parent 5a162c5840
commit 2abcdbe67d
No known key found for this signature in database
GPG key ID: 8CEDC00028084AEC
2 changed files with 18 additions and 4 deletions

View file

@ -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;

View file

@ -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`);
});