From 7704289751c3e8f6ac7a531594943d6d0a43a7e8 Mon Sep 17 00:00:00 2001 From: Andrey Lushnikov Date: Fri, 15 Sep 2023 10:26:20 -0700 Subject: [PATCH] browser(firefox): support relative paths for firefox videos (#27099) Firefox protocol requires absolute paths for video recording. Fixes https://github.com/microsoft/playwright/issues/27086 --- .../src/client/browserContext.ts | 3 +++ tests/library/video.spec.ts | 17 +++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/packages/playwright-core/src/client/browserContext.ts b/packages/playwright-core/src/client/browserContext.ts index 94f2a809b6d29a..2f1c587f7959ac 100644 --- a/packages/playwright-core/src/client/browserContext.ts +++ b/packages/playwright-core/src/client/browserContext.ts @@ -20,6 +20,7 @@ import { Frame } from './frame'; import * as network from './network'; import type * as channels from '@protocol/channels'; import fs from 'fs'; +import path from 'path'; import { ChannelOwner } from './channelOwner'; import { evaluationScript } from './clientHelper'; import { Browser } from './browser'; @@ -469,6 +470,8 @@ export async function prepareBrowserContextParams(options: BrowserContextOptions size: options.videoSize }; } + if (contextParams.recordVideo && contextParams.recordVideo.dir) + contextParams.recordVideo.dir = path.resolve(process.cwd(), contextParams.recordVideo.dir); return contextParams; } diff --git a/tests/library/video.spec.ts b/tests/library/video.spec.ts index e2857907bf8c52..55b97f2f804067 100644 --- a/tests/library/video.spec.ts +++ b/tests/library/video.spec.ts @@ -310,6 +310,23 @@ it.describe('screencast', () => { expect(fs.existsSync(path)).toBeTruthy(); }); + it('should work with relative path for recordVideo.dir', async ({ browser }, testInfo) => { + it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/27086' }); + const videosPath = path.relative(process.cwd(), testInfo.outputPath('')); + const size = { width: 320, height: 240 }; + const context = await browser.newContext({ + recordVideo: { + dir: videosPath, + size + }, + viewport: size, + }); + const page = await context.newPage(); + const videoPath = await page.video()!.path(); + await context.close(); + expect(fs.existsSync(videoPath)).toBeTruthy(); + }); + it('should expose video path blank popup', async ({ browser }, testInfo) => { const videosPath = testInfo.outputPath(''); const size = { width: 320, height: 240 };