Skip to content

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

chore: add placeholder for inputs in the snapshots (#37193)

Pavel Feldman2275968a942c
diff --git a/packages/injected/src/ariaSnapshot.ts b/packages/injected/src/ariaSnapshot.ts
index 09c3bef843..8c06d9e2e3 100644
--- a/packages/injected/src/ariaSnapshot.ts
+++ b/packages/injected/src/ariaSnapshot.ts
@@ -188,6 +188,11 @@ export function generateAriaTree(rootElement: Element, publicOptions: AriaTreeOp
const href = element.getAttribute('href')!;
ariaNode.props['url'] = href;
}
+
+ if (ariaNode.role === 'textbox' && element.hasAttribute('placeholder') && element.getAttribute('placeholder') !== ariaNode.name) {
+ const placeholder = element.getAttribute('placeholder')!;
+ ariaNode.props['placeholder'] = placeholder;
+ }
}
roleUtils.beginAriaCaches();
diff --git a/tests/page/page-aria-snapshot.spec.ts b/tests/page/page-aria-snapshot.spec.ts
index e08f4830da..5bb5cebc33 100644
--- a/tests/page/page-aria-snapshot.spec.ts
+++ b/tests/page/page-aria-snapshot.spec.ts
@@ -669,3 +669,20 @@ it('should not show unhidden children of aria-hidden elements', { annotation: {
expect(await page.locator('body').ariaSnapshot()).toBe('');
});
+
+it('should snapshot placeholder when different from the name', async ({ page }) => {
+ await page.setContent(`
+ <input placeholder="Placeholder">
+ `);
+ expect(await page.locator('body').ariaSnapshot()).toContainYaml(`
+ - textbox "Placeholder"
+ `);
+
+ await page.setContent(`
+ <input placeholder="Placeholder" aria-label="Label">
+ `);
+ expect(await page.locator('body').ariaSnapshot()).toContainYaml(`
+ - textbox "Label":
+ - /placeholder: Placeholder
+ `);
+});