From 0d12fbe0025729d372800934dc01a9283cb348b5 Mon Sep 17 00:00:00 2001 From: Max Schmitt Date: Wed, 23 Oct 2024 12:19:29 +0200 Subject: [PATCH] fix: have more friendly playwright-report error when opening TV via file:// (#33239) --- packages/trace-viewer/index.html | 21 +++++++++++++++-- tests/playwright-test/reporter-html.spec.ts | 26 +++++++++++++++++++++ 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/packages/trace-viewer/index.html b/packages/trace-viewer/index.html index bdd822dc0a..046eef0afb 100644 --- a/packages/trace-viewer/index.html +++ b/packages/trace-viewer/index.html @@ -30,8 +30,25 @@

For more information, please see the docs.

diff --git a/tests/playwright-test/reporter-html.spec.ts b/tests/playwright-test/reporter-html.spec.ts index d9e604f994..11169fadff 100644 --- a/tests/playwright-test/reporter-html.spec.ts +++ b/tests/playwright-test/reporter-html.spec.ts @@ -2510,6 +2510,32 @@ for (const useIntermediateMergeReport of [true, false] as const) { await testFilePathLink.click(); await expect(page.locator('.test-case-path')).toHaveText('Root describe'); }); + + test('should print a user-friendly warning when opening a trace via file:// protocol', async ({ runInlineTest, showReport, page }) => { + await runInlineTest({ + 'playwright.config.ts': ` + module.exports = { + projects: [{ + name: 'chromium', + use: { + browserName: 'chromium', + trace: 'on', + } + }] + }; + `, + 'a.test.js': ` + import { test } from '@playwright/test'; + test('passes', ({ page }) => {}); + `, + }, { reporter: 'dot,html' }, { PLAYWRIGHT_HTML_OPEN: 'never' }); + + const reportPath = path.join(test.info().outputPath(), 'playwright-report'); + await page.goto(url.pathToFileURL(path.join(reportPath, 'index.html')).toString()); + await page.getByRole('link', { name: 'View trace' }).click(); + await expect(page.locator('#fallback-error')).toContainText('The Playwright Trace Viewer must be loaded over the http:// or https:// protocols.'); + await expect(page.locator('#fallback-error')).toContainText(`npx playwright show-report ${reportPath.replace(/\\/g, '\\\\')}`); + }); }); }