diff --git a/packages/playwright/src/matchers/matchers.ts b/packages/playwright/src/matchers/matchers.ts index c0319e371f..97003cce1a 100644 --- a/packages/playwright/src/matchers/matchers.ts +++ b/packages/playwright/src/matchers/matchers.ts @@ -189,13 +189,20 @@ export function toHaveAccessibleDescription( export function toHaveAccessibleName( this: ExpectMatcherState, locator: LocatorEx, - expected: string | RegExp, - options?: { timeout?: number, ignoreCase?: boolean }, + expected: string | RegExp | (string | RegExp)[], + options: { timeout?: number, ignoreCase?: boolean, normalizeWhiteSpace?: boolean } = {} ) { - return toMatchText.call(this, 'toHaveAccessibleName', locator, 'Locator', async (isNot, timeout) => { - const expectedText = serializeExpectedTextValues([expected], { ignoreCase: options?.ignoreCase }); - return await locator._expect('to.have.accessible.name', { expectedText, isNot, timeout }); - }, expected, options); + if (Array.isArray(expected)) { + return toEqual.call(this, 'toHaveAccessibleName', locator, 'Locator', async (isNot, timeout) => { + const expectedText = serializeExpectedTextValues(expected, { normalizeWhiteSpace: true, ignoreCase: options.ignoreCase }); + return await locator._expect('to.have.accessible.name.array', { expectedText, isNot, timeout }); + }, expected, options); + } else { + return toMatchText.call(this, 'toHaveAccessibleName', locator, 'Locator', async (isNot, timeout) => { + const expectedText = serializeExpectedTextValues([expected], { normalizeWhiteSpace: true, ignoreCase: options.ignoreCase }); + return await locator._expect('to.have.accessible.name', { expectedText, isNot, timeout }); + }, expected, options); + } } export function toHaveAttribute( diff --git a/packages/playwright/types/test.d.ts b/packages/playwright/types/test.d.ts index ae02d1506e..9445ed0a70 100644 --- a/packages/playwright/types/test.d.ts +++ b/packages/playwright/types/test.d.ts @@ -7898,7 +7898,7 @@ interface LocatorAssertions { * @param name Expected accessible name. * @param options */ - toHaveAccessibleName(name: string|RegExp, options?: { + toHaveAccessibleName(name: string | RegExp | (string | RegExp)[], options?: { /** * Whether to perform case-insensitive match. * [`ignoreCase`](https://playwright.dev/docs/api/class-locatorassertions#locator-assertions-to-have-accessible-name-option-ignore-case)