Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

fix(mcp): snapshot for ai fixes (#37527)

Pavel Feldmanda333232e715
diff --git a/packages/injected/src/ariaSnapshot.ts b/packages/injected/src/ariaSnapshot.ts
index 2dc9e19641..a1e1afd425 100644
--- a/packages/injected/src/ariaSnapshot.ts
+++ b/packages/injected/src/ariaSnapshot.ts
@@ -302,7 +302,7 @@ function normalizeGenericRoles(node: AriaNode) {
}
// Only remove generic that encloses one element, logical grouping still makes sense, even if it is not ref-able.
- const removeSelf = node.role === 'generic' && result.length <= 1 && result.every(c => typeof c !== 'string' && !!c.ref);
+ const removeSelf = node.role === 'generic' && !node.name && result.length <= 1 && result.every(c => typeof c !== 'string' && !!c.ref);
if (removeSelf)
return result;
node.children = result;
diff --git a/tests/page/page-aria-snapshot-ai.spec.ts b/tests/page/page-aria-snapshot-ai.spec.ts
index 816ac4a688..982cc120cb 100644
--- a/tests/page/page-aria-snapshot-ai.spec.ts
+++ b/tests/page/page-aria-snapshot-ai.spec.ts
@@ -439,3 +439,12 @@ it('should collapse inline generic nodes', async ({ page }) => {
- generic [ref=e12]: 1,200
`);
});
+
+it('should not remove generic nodes with title', async ({ page }) => {
+ await page.setContent(`<div title="Element title">Element content</div>`);
+
+ const snapshot = await snapshotForAI(page);
+ expect(snapshot).toContainYaml(`
+ - generic "Element title" [ref=e2]
+ `);
+});