Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
chore(ai snapshot): dont error on navigating childframe (#35951)
Simon Knottb9055fe9fc8e
diff --git a/packages/playwright-core/src/server/page.ts b/packages/playwright-core/src/server/page.tsindex 5ada5e2ab8..b91499d190 100644--- a/packages/playwright-core/src/server/page.ts+++ b/packages/playwright-core/src/server/page.ts@@ -1024,8 +1024,12 @@ async function snapshotFrameForAI(frame: frames.Frame, frameOrdinal: number, fra}const frameOrdinal = frameIds.length + 1;frameIds.push(child.frame._id);- const childSnapshot = await snapshotFrameForAI(child.frame, frameOrdinal, frameIds);- result.push(line + ':', ...childSnapshot.map(l => leadingSpace + ' ' + l));+ try {+ const childSnapshot = await snapshotFrameForAI(child.frame, frameOrdinal, frameIds);+ result.push(line + ':', ...childSnapshot.map(l => leadingSpace + ' ' + l));+ } catch {+ result.push(line);+ }}return result;}diff --git a/tests/assets/redirectloop1.html b/tests/assets/redirectloop1.htmlindex 27fab61ca8..d542c4e9e4 100644--- a/tests/assets/redirectloop1.html+++ b/tests/assets/redirectloop1.html@@ -1,8 +1,9 @@<script>setTimeout(() => {+ const depth = new URLSearchParams(window.location.hash).get('depth') ?? '10';const iter = window.localStorage.iter || '';window.localStorage.iter = iter + 'a';- if (iter.length === 10)+ if (iter.length === +depth)return;window.location.href = window.location.href.replace('loop1', 'loop2');}, 1);diff --git a/tests/page/page-aria-snapshot-ai.spec.ts b/tests/page/page-aria-snapshot-ai.spec.tsindex 1491883b62..c00b3e2c3e 100644--- a/tests/page/page-aria-snapshot-ai.spec.ts+++ b/tests/page/page-aria-snapshot-ai.spec.ts@@ -218,3 +218,16 @@ it('should include cursor pointer hint', async ({ page }) => {- button \"Button\" [ref=e2] [cursor=pointer]`);});++it('should gracefully fallback when child frame cant be captured', async ({ page, server }) => {+ await page.setContent(`+ <p>Test</p>+ <iframe src="${server.PREFIX}/redirectloop1.html#depth=100000"></iframe>+ `, { waitUntil: 'domcontentloaded' });+ const snapshot = await snapshotForAI(page);+ expect(snapshot).toContainYaml(`+ - generic [ref=e1]:+ - paragraph [ref=e2]: Test+ - iframe [ref=e3]+ `);+});