diff --git a/packages/playwright-core/src/server/page.ts b/packages/playwright-core/src/server/page.ts index 7753982667617..7f8f7b7163a02 100644 --- a/packages/playwright-core/src/server/page.ts +++ b/packages/playwright-core/src/server/page.ts @@ -1034,7 +1034,7 @@ async function snapshotFrameForAI(progress: Progress, frame: frames.Frame, frame const lines = snapshot.split('\n'); const result = []; for (const line of lines) { - const match = line.match(/^(\s*)- iframe (?:\[active\] )?\[ref=(.*)\]/); + const match = line.match(/^(\s*)- iframe (?:\[active\] )?\[ref=([^\]]*)\]/); if (!match) { result.push(line); continue; diff --git a/tests/page/page-aria-snapshot-ai.spec.ts b/tests/page/page-aria-snapshot-ai.spec.ts index dac1bc3fcbf47..c7afd03cf34da 100644 --- a/tests/page/page-aria-snapshot-ai.spec.ts +++ b/tests/page/page-aria-snapshot-ai.spec.ts @@ -374,3 +374,21 @@ it('return empty snapshot when iframe is not loaded', { annotation: { type: 'iss - iframe [ref=e3] `); }); + +it('should support many properties on iframes', async ({ page }) => { + await page.setContent(` + + + `); + + // Test 1: Focus the input inside the iframe + await page.frameLocator('iframe').locator('#iframe-input').focus(); + const inputInIframeFocusedSnapshot = await snapshotForAI(page); + + expect(inputInIframeFocusedSnapshot).toContainYaml(` + - generic [ref=e1]: + - textbox "Regular input" [ref=e2] + - iframe [active] [ref=e3] [cursor=pointer]: + - textbox "Input in iframe" [active] [ref=f1e2] + `); +});