Skip to content

Commit 8eb851e

Browse files
committed
fix(reporter-html): enhance user-friendly warning for trace viewer with platform-specific command
1 parent 221c73b commit 8eb851e

File tree

1 file changed

+30
-8
lines changed

1 file changed

+30
-8
lines changed

tests/playwright-test/reporter-html.spec.ts

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import fs from 'fs';
1818
import path from 'path';
1919
import url from 'url';
20+
import process from 'process';
2021
import { test as baseTest, expect as baseExpect, createImage } from './playwright-test-fixtures';
2122
import type { HttpServer } from '../../packages/playwright-core/lib/server/utils/httpServer';
2223
import { startHtmlReportServer } from '../../packages/playwright/lib/reporters/html';
@@ -2943,9 +2944,13 @@ for (const useIntermediateMergeReport of [true, false] as const) {
29432944
await expect(page.locator('.test-case-path')).toHaveText('Root describe');
29442945
});
29452946

2946-
test('should print a user-friendly warning when opening a trace via file:// protocol', async ({ runInlineTest, showReport, page }) => {
2947-
await runInlineTest({
2948-
'playwright.config.ts': `
2947+
test('should print a user-friendly warning when opening a trace via file:// protocol', async ({
2948+
runInlineTest,
2949+
page,
2950+
}) => {
2951+
await runInlineTest(
2952+
{
2953+
'playwright.config.ts': `
29492954
module.exports = {
29502955
projects: [{
29512956
name: 'chromium',
@@ -2956,19 +2961,36 @@ for (const useIntermediateMergeReport of [true, false] as const) {
29562961
}]
29572962
};
29582963
`,
2959-
'a.test.js': `
2964+
'a.test.js': `
29602965
import { test } from '@playwright/test';
29612966
test('passes', ({ page }) => {});
29622967
`,
2963-
}, { reporter: 'dot,html' }, { PLAYWRIGHT_HTML_OPEN: 'never' });
2968+
},
2969+
{ reporter: 'dot,html' },
2970+
{ PLAYWRIGHT_HTML_OPEN: 'never' }
2971+
);
29642972

29652973
const reportPath = path.join(test.info().outputPath(), 'playwright-report');
2966-
await page.goto(url.pathToFileURL(path.join(reportPath, 'index.html')).toString());
2974+
2975+
await page.goto(
2976+
url.pathToFileURL(path.join(reportPath, 'index.html')).toString()
2977+
);
29672978
await page.getByRole('link', { name: 'View trace' }).click();
2968-
await expect(page.locator('#fallback-error')).toContainText('The Playwright Trace Viewer must be loaded over the http:// or https:// protocols.');
2969-
await expect(page.locator('#fallback-error')).toContainText(`npx playwright show-report ${reportPath.replace(/\\/g, '\\\\')}`);
2979+
2980+
await expect(page.locator('#fallback-error')).toContainText(
2981+
'The Playwright Trace Viewer must be loaded over the http:// or https:// protocols.'
2982+
);
2983+
2984+
const expectedPath =
2985+
process.platform === 'win32'
2986+
? reportPath.replace(/\\/g, '\\\\')
2987+
: reportPath;
2988+
2989+
const expectedCmd = `npx playwright show-report "${expectedPath}"`;
2990+
await expect(page.locator('#fallback-error')).toContainText(expectedCmd);
29702991
});
29712992

2993+
29722994
test('should not collate identical file names in different project directories', async ({ runInlineTest, page }) => {
29732995
await runInlineTest({
29742996
'playwright.config.ts': `

0 commit comments

Comments
 (0)