feat: do not let users pass userDataDir to browserType.launch() (#974)

We now have a separate method for this - `browserType.launchPersistent`.
This will probably save our users quite some time.
This commit is contained in:
Andrey Lushnikov 2020-02-12 19:32:23 -08:00 committed by GitHub
parent b7f48f4603
commit d735de5347
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 0 deletions

View file

@ -50,6 +50,8 @@ export class Chromium implements BrowserType {
}
async launch(options?: LaunchOptions & { slowMo?: number }): Promise<CRBrowser> {
if (options && (options as any).userDataDir)
throw new Error('userDataDir option is not supported in `browserType.launch`. Use `browserType.launchPersistent` instead');
const { browserServer, transport } = await this._launchServer(options, 'local');
const browser = await CRBrowser.connect(transport!, options && options.slowMo);
// Hack: for typical launch scenario, ensure that close waits for actual process termination.

View file

@ -60,6 +60,8 @@ export class Firefox implements BrowserType {
}
async launch(options?: LaunchOptions & { slowMo?: number }): Promise<FFBrowser> {
if (options && (options as any).userDataDir)
throw new Error('userDataDir option is not supported in `browserType.launch`. Use `browserType.launchPersistent` instead');
const { browserServer, transport } = await this._launchServer(options, 'local');
const browser = await FFBrowser.connect(transport!, options && options.slowMo);
// Hack: for typical launch scenario, ensure that close waits for actual process termination.

View file

@ -62,6 +62,8 @@ export class WebKit implements BrowserType {
}
async launch(options?: LaunchOptions & { slowMo?: number }): Promise<WKBrowser> {
if (options && (options as any).userDataDir)
throw new Error('userDataDir option is not supported in `browserType.launch`. Use `browserType.launchPersistent` instead');
const { browserServer, transport } = await this._launchServer(options, 'local');
const browser = await WKBrowser.connect(transport!, options && options.slowMo);
// Hack: for typical launch scenario, ensure that close waits for actual process termination.

View file

@ -39,6 +39,12 @@ module.exports.describe = function({testRunner, expect, defaultBrowserOptions, p
await neverResolves;
expect(error.message).toContain('Protocol error');
});
it('should throw if userDataDir option is passed', async() => {
let waitError = null;
const options = Object.assign({}, defaultBrowserOptions, {userDataDir: 'random-path'});
await playwright.launch(options).catch(e => waitError = e);
expect(waitError.message).toContain('launchPersistent');
});
it('should reject if executable path is invalid', async({server}) => {
let waitError = null;
const options = Object.assign({}, defaultBrowserOptions, {executablePath: 'random-invalid-path'});