Create userDataDir if it does not exist (#9483)

This commit is contained in:
Maximilian Hils 2021-10-14 20:19:52 +02:00 committed by GitHub
parent 584014f6fa
commit 84a70eae2f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

View File

@ -146,7 +146,11 @@ export abstract class BrowserType extends SdkObject {
const artifactsDir = await fs.promises.mkdtemp(ARTIFACTS_FOLDER);
tempDirectories.push(artifactsDir);
if (!userDataDir) {
if (userDataDir) {
// Firefox bails if the profile directory does not exist, Chrome creates it. We ensure consistent behavior here.
if (!await existsAsync(userDataDir))
await fs.promises.mkdir(userDataDir, { recursive: true, mode: 0o700 });
} else {
userDataDir = await fs.promises.mkdtemp(path.join(os.tmpdir(), `playwright_${this._name}dev_profile-`));
tempDirectories.push(userDataDir);
}

View File

@ -17,6 +17,7 @@
import { playwrightTest as it, expect } from './config/browserTest';
import fs from 'fs';
import path from 'path';
it('should support hasTouch option', async ({ server, launchPersistent }) => {
const { page } = await launchPersistent({ hasTouch: true });
@ -119,6 +120,13 @@ it('should restore state from userDataDir', async ({ browserType, browserOptions
await browserContext3.close();
});
it('should create userDataDir if it does not exist', async ({ createUserDataDir, browserType, browserOptions }) => {
const userDataDir = path.join(await createUserDataDir(), 'nonexisting');
const context = await browserType.launchPersistentContext(userDataDir, browserOptions);
await context.close();
expect(fs.readdirSync(userDataDir).length).toBeGreaterThan(0);
});
it('should restore cookies from userDataDir', async ({ browserType, browserOptions, server, createUserDataDir, platform, channel }) => {
it.fixme(platform === 'win32' && channel === 'chrome');
it.slow();