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
chore: more aria snapshot fixes (#33534)
Dmitry Gozman33f9c8279c43
diff --git a/packages/playwright-core/src/server/injected/ariaSnapshot.ts b/packages/playwright-core/src/server/injected/ariaSnapshot.tsindex 06de76c820..b2352a1b9c 100644--- a/packages/playwright-core/src/server/injected/ariaSnapshot.ts+++ b/packages/playwright-core/src/server/injected/ariaSnapshot.ts@@ -300,7 +300,8 @@ export function renderAriaTree(ariaNode: AriaNode, options?: { mode?: 'raw' | 'r}let key = ariaNode.role;- if (ariaNode.name) {+ // Yaml has a limit of 1024 characters per key, and we leave some space for role and attributes.+ if (ariaNode.name && ariaNode.name.length <= 900) {const name = renderString(ariaNode.name);if (name) {const stringifiedName = name.startsWith('/') && name.endsWith('/') ? name : JSON.stringify(name);diff --git a/packages/playwright/src/matchers/toMatchAriaSnapshot.ts b/packages/playwright/src/matchers/toMatchAriaSnapshot.tsindex 47e9f70441..f3e7d47a6e 100644--- a/packages/playwright/src/matchers/toMatchAriaSnapshot.ts+++ b/packages/playwright/src/matchers/toMatchAriaSnapshot.ts@@ -79,7 +79,7 @@ export async function toMatchAriaSnapshot(if (notFound) {return {pass: this.isNot,- message: () => messagePrefix + `Expected: ${this.utils.printExpected(expected)}\nReceived: ${EXPECTED_COLOR('not found')}` + callLogText(log),+ message: () => messagePrefix + `Expected: ${this.utils.printExpected(expected)}\nReceived: ${EXPECTED_COLOR('<element not found>')}` + callLogText(log),name: 'toMatchAriaSnapshot',expected,};diff --git a/tests/page/page-aria-snapshot.spec.ts b/tests/page/page-aria-snapshot.spec.tsindex 22ae280b4d..a7937e9be5 100644--- a/tests/page/page-aria-snapshot.spec.ts+++ b/tests/page/page-aria-snapshot.spec.ts@@ -479,16 +479,16 @@ it('should escape yaml text in text nodes', async ({ page }) => {`);});-it.fixme('should handle long strings', async ({ page }) => {+it('should handle long strings', async ({ page }) => {+ const s = 'a'.repeat(10000);await page.setContent(`<a href='about:blank'>- <div role='region'>${'a'.repeat(100000)}</div>+ <div role='region'>${s}</div></a>`);- const trimmed = 'a'.repeat(1000);await checkAndMatchSnapshot(page.locator('body'), `- - link "${trimmed}":- - region: "${trimmed}"+ - link:+ - region: ${s}`);});diff --git a/tests/page/to-match-aria-snapshot.spec.ts b/tests/page/to-match-aria-snapshot.spec.tsindex 40709909ce..05a02f369b 100644--- a/tests/page/to-match-aria-snapshot.spec.ts+++ b/tests/page/to-match-aria-snapshot.spec.ts@@ -640,17 +640,6 @@ test('call log should contain actual snapshot', async ({ page }) => {expect(stripAnsi(error.message)).toContain(`- unexpected value "- heading "todos" [level=1]"`);});-test.fixme('should normalize whitespace when matching accessible name', async ({ page }) => {- await page.setContent(`- <button>hello world</button>- `);- await expect(page.locator('body')).toMatchAriaSnapshot(`- - |- button "hello- world"- `);-});-test('should parse attributes', async ({ page }) => {{await page.setContent(`diff --git a/tests/playwright-test/update-aria-snapshot.spec.ts b/tests/playwright-test/update-aria-snapshot.spec.tsindex e6d76da282..2a831521a7 100644--- a/tests/playwright-test/update-aria-snapshot.spec.ts+++ b/tests/playwright-test/update-aria-snapshot.spec.ts@@ -377,3 +377,22 @@ test('should generate baseline for input values', async ({ runInlineTest }, testconst result2 = await runInlineTest({});expect(result2.exitCode).toBe(0);});++test('should not update snapshots when locator did not match', async ({ runInlineTest }, testInfo) => {+ const result = await runInlineTest({+ 'a.spec.ts': `+ import { test, expect } from '@playwright/test';+ test('test', async ({ page }) => {+ await page.setContent('<h1>hello</h1>');+ await expect(page.locator('div')).toMatchAriaSnapshot('- heading', { timeout: 3000 });+ });+ `,+ }, { 'update-snapshots': true });++ expect(result.exitCode).toBe(1);+ const patchPath = testInfo.outputPath('test-results/rebaselines.patch');+ expect(fs.existsSync(patchPath)).toBe(false);+ expect(result.output).not.toContain('New baselines created');+ expect(result.output).toContain('Expected: "- heading"');+ expect(result.output).toContain('Received: <element not found>');+});