Skip to content

Commit

Permalink
fix: support relative downloadsPath directory for downloads (#6402)
Browse files Browse the repository at this point in the history
  • Loading branch information
mxschmitt authored May 5, 2021
1 parent 5509527 commit ab850af
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/server/browserType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
}
15 changes: 15 additions & 0 deletions tests/downloads-path.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}) => {
Expand Down Expand Up @@ -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>`);
Expand Down

0 comments on commit ab850af

Please sign in to comment.