Skip to content

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

chore(aria): don't ignore top-level `containerMode` (#36471)

Simon Knottb17e2ebb2443
diff --git a/packages/playwright-core/src/utils/isomorphic/ariaSnapshot.ts b/packages/playwright-core/src/utils/isomorphic/ariaSnapshot.ts
index ffbd50ddef..48d1a627d0 100644
--- a/packages/playwright-core/src/utils/isomorphic/ariaSnapshot.ts
+++ b/packages/playwright-core/src/utils/isomorphic/ariaSnapshot.ts
@@ -243,9 +243,10 @@ export function parseAriaSnapshot(yaml: YamlLibrary, text: string, options: yaml
convertSeq(fragment, yamlDoc.contents as yamlTypes.YAMLSeq);
if (errors.length)
return { errors, fragment: emptyFragment };
- if (fragment.children?.length === 1)
- return { fragment: fragment.children[0], errors };
- return { fragment, errors };
+ // `- button` should target the button, not its parent.
+ if (fragment.children?.length === 1 && (!fragment.containerMode || fragment.containerMode === 'contain'))
+ return { fragment: fragment.children[0], errors: [] };
+ return { fragment, errors: [] };
}
const emptyFragment: AriaTemplateRoleNode = { kind: 'role', role: 'fragment' };
diff --git a/tests/page/to-match-aria-snapshot.spec.ts b/tests/page/to-match-aria-snapshot.spec.ts
index f929f1b11a..faf35bede2 100644
--- a/tests/page/to-match-aria-snapshot.spec.ts
+++ b/tests/page/to-match-aria-snapshot.spec.ts
@@ -791,3 +791,31 @@ test('should allow restoring contain mode inside deep-equal', async ({ page }) =
- listitem: 1.1
`);
});
+
+test('top-level deep-equal', { annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright/issues/36456' } }, async ({ page }) => {
+ await page.setContent(`
+ <ul>
+ <li>
+ <ul>
+ <li>1.1</li>
+ <li>1.2</li>
+ </ul>
+ </li>
+ </ul>
+ `);
+
+ const error = await expect(page.locator('body')).toMatchAriaSnapshot(`
+ - /children: deep-equal
+ - list
+ `, { timeout: 1000 }).catch(e => e);
+
+ expect(stripAnsi(error.message)).toContain(`
+- - /children: deep-equal
+- - list
++ - list:
++ - listitem:
++ - list:
++ - listitem: "1.1"
++ - listitem: "1.2"
+ `.trim());
+});