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
fix(aria): do not count whitespace-only contributors as name sources (#43317)
Pavel Feldman90629d720440
diff --git a/packages/injected/src/roleUtils.ts b/packages/injected/src/roleUtils.tsindex 6f8f295a81..649525f049 100644--- a/packages/injected/src/roleUtils.ts+++ b/packages/injected/src/roleUtils.ts@@ -1071,7 +1071,9 @@ function getTextAlternativeInternal(element: Element, options: AccessibleNameOptif (options.outDerivedFromContent && insideTargetElement(options) && trimFlatString(accessibleName.text))options.outDerivedFromContent.value = true;// This element owns the accumulated content - record it alongside the descendants it was computed from.- accessibleName.elements?.add(element);+ // Whitespace alone is not content, e.g. the spacing around an inline-block icon.+ if (trimFlatString(accessibleName.text))+ accessibleName.elements?.add(element);return accessibleName;}}diff --git a/tests/page/page-aria-snapshot-ai.spec.ts b/tests/page/page-aria-snapshot-ai.spec.tsindex 3068921df8..fad95eea72 100644--- a/tests/page/page-aria-snapshot-ai.spec.ts+++ b/tests/page/page-aria-snapshot-ai.spec.ts@@ -397,9 +397,12 @@ it('should omit redundant name when a contributor is a skipped leaf generic', asit('should keep the name when the contributing wrapper collapses into repeating text', async ({ page }) => {it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/41985' });+ it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/43315' });// The outer span is marked as represented while it still wraps the icon. Once the nameless// image is dropped, the span collapses into a lone text repeating the button's name and removes// itself, so the button must keep the name derived from it.+ // A wrapper that only adds whitespace to the name - a stray text node, or the spacing around an+ // inline-block icon - is not where the name comes from.await page.setContent(`<button><span>@@ -411,11 +414,16 @@ it('should keep the name when the contributing wrapper collapses into repeating<span>Add New Item</span></span></button>+ <button><span>\n <svg aria-hidden="true"></svg></span>New survey</button>+ <button><span><svg aria-hidden="true" style="width: 1em; height: 1em; display: inline-block"></svg></span>Edit survey</button>`);const snapshot = await snapshotForAI(page);expect(snapshot).toContainYaml(`- - button "Add New Item" [ref=e2]+ - generic [active] [ref=e1]:+ - button "Add New Item" [ref=e2]+ - button "New survey" [ref=e7]+ - button "Edit survey" [ref=e10]`);});