From c66c4fdf640c942eae1f72c219ef77397294c9cc Mon Sep 17 00:00:00 2001 From: Simon Knott Date: Thu, 27 Feb 2025 08:42:34 +0100 Subject: [PATCH] feat(pageSnapshot): add header comment with info --- packages/playwright/src/index.ts | 3 ++- tests/playwright-test/playwright.artifacts.spec.ts | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/playwright/src/index.ts b/packages/playwright/src/index.ts index 68b29bf3d6..fd506ca113 100644 --- a/packages/playwright/src/index.ts +++ b/packages/playwright/src/index.ts @@ -630,7 +630,8 @@ class ArtifactsRecorder { this._pageSnapshotRecorder = new SnapshotRecorder(this, pageSnapshot, 'pageSnapshot', 'text/plain', '.snapshot.yml', async (page, path) => { const ariaSnapshot = await page.locator('body').ariaSnapshot({ timeout: 5000 }); - await fs.promises.writeFile(path, ariaSnapshot); + const header = `# ${this._testInfo.titlePath.join(' >> ')}\n# ARIA snapshot of the page contents after test ${this._testInfo._isFailure() ? 'failed' : 'finished'}\n`; + await fs.promises.writeFile(path, header + ariaSnapshot); }); } diff --git a/tests/playwright-test/playwright.artifacts.spec.ts b/tests/playwright-test/playwright.artifacts.spec.ts index d54fe5265c..7ec6d4d166 100644 --- a/tests/playwright-test/playwright.artifacts.spec.ts +++ b/tests/playwright-test/playwright.artifacts.spec.ts @@ -459,6 +459,12 @@ test('should work with pageSnapshot: on', async ({ runInlineTest }, testInfo) => ' test-failed-1.snapshot.yml', ' test-failed-2.snapshot.yml', ]); + + expect(fs.readFileSync(testInfo.outputPath('test-results', 'artifacts-failing', 'test-failed-1.snapshot.yml'), { encoding: 'utf-8' })).toEqual(` +# artifacts.spec.ts >> failing +# ARIA snapshot of the page contents after test failed +- text: I am the page + `.trim()); }); test('should work with pageSnapshot: only-on-failure', async ({ runInlineTest }, testInfo) => {