fix: support relative downloadsPath directory for downloads (#6402)

This commit is contained in:
Max Schmitt 2021-05-05 17:07:10 +02:00 committed by GitHub
parent 5509527917
commit ab850afb45
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 2 deletions

View file

@ -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 };
}

View file

@ -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>`);