From 7456dea56329f20c221588338fd800aafb37dbbf Mon Sep 17 00:00:00 2001 From: anait-airiian Date: Thu, 24 Oct 2024 18:41:46 +0200 Subject: [PATCH] feat(aria): handle array in the injectedScript and write a test This commit includes the handling accessible.name.array References #32593 --- .../src/server/injected/injectedScript.ts | 2 ++ tests/page/expect-misc.spec.ts | 27 +++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/packages/playwright-core/src/server/injected/injectedScript.ts b/packages/playwright-core/src/server/injected/injectedScript.ts index 6446d16966..8d39aaa388 100644 --- a/packages/playwright-core/src/server/injected/injectedScript.ts +++ b/packages/playwright-core/src/server/injected/injectedScript.ts @@ -1324,6 +1324,8 @@ export class InjectedScript { received = elements.map(e => options.useInnerText ? (e as HTMLElement).innerText : elementText(new Map(), e).full); else if (expression === 'to.have.class.array') received = elements.map(e => e.classList.toString()); + else if (expression === 'to.have.accessible.name.array') + received = elements.map(e => getElementAccessibleName(e, false)); if (received && options.expectedText) { // "To match an array" is "to contain an array" + "equal length" diff --git a/tests/page/expect-misc.spec.ts b/tests/page/expect-misc.spec.ts index 2242a55378..773f6e3cb6 100644 --- a/tests/page/expect-misc.spec.ts +++ b/tests/page/expect-misc.spec.ts @@ -433,6 +433,33 @@ test('toHaveAccessibleName', async ({ page }) => { await expect(page.locator('div')).toHaveAccessibleName(/hello/, { ignoreCase: true }); }); +test('toHaveAccessibleName should accept array of names for multiple elements', async ({ page }) => { + await page.setContent(` + + + + + + + + + + + + + + + + +
Cell A1Cell B1Cell C1
Cell A2Cell B2Cell C2
Cell A3Cell B3Cell C3
+ `); + await expect(page.getByRole('row')).toHaveAccessibleName([ + 'Cell A1 Cell B1 Cell C1', + 'Cell A2 Cell B2 Cell C2', + 'Cell A3 Cell B3 Cell C3', + ]); +}); + test('toHaveAccessibleDescription', async ({ page }) => { await page.setContent(`