fix: support relative downloadsPath directory for downloads (#6402)
This commit is contained in:
parent
5509527917
commit
ab850afb45
|
|
@ -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 };
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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>`);
|
||||
|
|
|
|||
Loading…
Reference in a new issue