From 988c876a6276f29a945e88288f05b58b500abe9c Mon Sep 17 00:00:00 2001 From: anait-airiian Date: Thu, 24 Oct 2024 18:51:45 +0200 Subject: [PATCH] feat(aria): make assertion agile and add the tests The expected string can be asserting softly without being equivalent to the actual string References #32593 --- packages/playwright/src/matchers/matchers.ts | 4 ++-- tests/page/expect-misc.spec.ts | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/playwright/src/matchers/matchers.ts b/packages/playwright/src/matchers/matchers.ts index 97003cce1a..7b1ff6f5d9 100644 --- a/packages/playwright/src/matchers/matchers.ts +++ b/packages/playwright/src/matchers/matchers.ts @@ -194,12 +194,12 @@ export function toHaveAccessibleName( ) { if (Array.isArray(expected)) { return toEqual.call(this, 'toHaveAccessibleName', locator, 'Locator', async (isNot, timeout) => { - const expectedText = serializeExpectedTextValues(expected, { normalizeWhiteSpace: true, ignoreCase: options.ignoreCase }); + const expectedText = serializeExpectedTextValues(expected, { matchSubstring: true, 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 }); + const expectedText = serializeExpectedTextValues([expected], { matchSubstring: true, normalizeWhiteSpace: true, ignoreCase: options.ignoreCase }); return await locator._expect('to.have.accessible.name', { expectedText, isNot, timeout }); }, expected, options); } diff --git a/tests/page/expect-misc.spec.ts b/tests/page/expect-misc.spec.ts index 773f6e3cb6..25599d3776 100644 --- a/tests/page/expect-misc.spec.ts +++ b/tests/page/expect-misc.spec.ts @@ -458,6 +458,12 @@ test('toHaveAccessibleName should accept array of names for multiple elements', 'Cell A2 Cell B2 Cell C2', 'Cell A3 Cell B3 Cell C3', ]); + await expect(page.getByRole('row')).toHaveAccessibleName(['Cell A1 Cell B1 Cell C1', + 'Cell A2 Cell B2 Cell C2', + 'Cell A3 Cell B3',]); + await expect(page.getByRole('row')).toHaveAccessibleName(['cell a1 cell b1 cell C1', + 'cell A2 Cell b2 Cell c2', + 'Cell a3 Cell b3 cell C3',], { ignoreCase: true }); }); test('toHaveAccessibleDescription', async ({ page }) => {