diff --git a/src/server/browserType.ts b/src/server/browserType.ts index 818339aa0fcc7..575e9ee25ddd7 100644 --- a/src/server/browserType.ts +++ b/src/server/browserType.ts @@ -271,8 +271,10 @@ function copyTestHooks(from: object, to: object) { function validateLaunchOptions<Options extends types.LaunchOptions>(options: Options): Options { const { devtools = false } = options; - let { headless = !devtools } = options; + let { headless = !devtools, downloadsPath } = options; if (debugMode()) headless = false; - return { ...options, devtools, headless }; + if (downloadsPath && !path.isAbsolute(downloadsPath)) + downloadsPath = path.join(process.cwd(), downloadsPath); + return { ...options, devtools, headless, downloadsPath }; } diff --git a/tests/downloads-path.spec.ts b/tests/downloads-path.spec.ts index 11ff43c2d2ca8..a5858da1723d0 100644 --- a/tests/downloads-path.spec.ts +++ b/tests/downloads-path.spec.ts @@ -16,6 +16,7 @@ import { playwrightTest as it, expect } from './config/browserTest'; import fs from 'fs'; +import path from 'path'; it.describe('downloads path', () => { it.beforeEach(async ({server}) => { @@ -71,6 +72,20 @@ it.describe('downloads path', () => { await downloadsBrowser.close(); }); + it('should report downloads in downloadsPath folder with a relative path', async ({browserType, browserOptions, server}, testInfo) => { + const downloadsBrowser = await browserType.launch({ ...browserOptions, downloadsPath: path.relative(process.cwd(), testInfo.outputPath('')) }); + const page = await downloadsBrowser.newPage({ acceptDownloads: true }); + await page.setContent(`<a href="${server.PREFIX}/download">download</a>`); + const [ download ] = await Promise.all([ + page.waitForEvent('download'), + page.click('a') + ]); + const downloadPath = await download.path(); + expect(downloadPath.startsWith(testInfo.outputPath(''))).toBeTruthy(); + await page.close(); + await downloadsBrowser.close(); + }); + it('should accept downloads in persistent context', async ({launchPersistent, server}, testInfo) => { const { context, page } = await launchPersistent({ acceptDownloads: true, downloadsPath: testInfo.outputPath('') }); await page.setContent(`<a href="${server.PREFIX}/download">download</a>`);