fix(launch): throw upon page argument when non-persistent (#1144)

This commit is contained in:
Pavel Feldman 2020-02-27 14:09:24 -08:00 committed by GitHub
parent 9d6aa967f3
commit dc161df063
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 6 deletions

View file

@ -178,6 +178,8 @@ export class Chromium implements BrowserType {
throw new Error('Pass userDataDir parameter instead of specifying --user-data-dir argument'); throw new Error('Pass userDataDir parameter instead of specifying --user-data-dir argument');
if (args.find(arg => arg.startsWith('--remote-debugging-'))) if (args.find(arg => arg.startsWith('--remote-debugging-')))
throw new Error('Playwright manages remote debugging connection itself.'); throw new Error('Playwright manages remote debugging connection itself.');
if (launchType !== 'persistent' && args.find(arg => !arg.startsWith('-')))
throw new Error('Arguments can not specify page to be opened');
const chromeArguments = [...DEFAULT_ARGS]; const chromeArguments = [...DEFAULT_ARGS];
chromeArguments.push(`--user-data-dir=${userDataDir}`); chromeArguments.push(`--user-data-dir=${userDataDir}`);

View file

@ -85,7 +85,7 @@ export class Firefox implements BrowserType {
return browserContext; return browserContext;
} }
private async _launchServer(options: LaunchOptions = {}, connectionType: LaunchType, userDataDir?: string, port?: number): Promise<{ browserServer: BrowserServer, transport?: ConnectionTransport }> { private async _launchServer(options: LaunchOptions = {}, launchType: LaunchType, userDataDir?: string, port?: number): Promise<{ browserServer: BrowserServer, transport?: ConnectionTransport }> {
const { const {
ignoreDefaultArgs = false, ignoreDefaultArgs = false,
args = [], args = [],
@ -107,9 +107,9 @@ export class Firefox implements BrowserType {
} }
if (!ignoreDefaultArgs) if (!ignoreDefaultArgs)
firefoxArguments.push(...this._defaultArgs(options, userDataDir!, port || 0)); firefoxArguments.push(...this._defaultArgs(options, launchType, userDataDir!, port || 0));
else if (Array.isArray(ignoreDefaultArgs)) else if (Array.isArray(ignoreDefaultArgs))
firefoxArguments.push(...this._defaultArgs(options, userDataDir!, port || 0).filter(arg => !ignoreDefaultArgs.includes(arg))); firefoxArguments.push(...this._defaultArgs(options, launchType, userDataDir!, port || 0).filter(arg => !ignoreDefaultArgs.includes(arg)));
else else
firefoxArguments.push(...args); firefoxArguments.push(...args);
@ -155,8 +155,8 @@ export class Firefox implements BrowserType {
const timeoutError = new TimeoutError(`Timed out after ${timeout} ms while trying to connect to Firefox!`); const timeoutError = new TimeoutError(`Timed out after ${timeout} ms while trying to connect to Firefox!`);
const match = await waitForLine(launchedProcess, launchedProcess.stdout, /^Juggler listening on (ws:\/\/.*)$/, timeout, timeoutError); const match = await waitForLine(launchedProcess, launchedProcess.stdout, /^Juggler listening on (ws:\/\/.*)$/, timeout, timeoutError);
const browserWSEndpoint = match[1]; const browserWSEndpoint = match[1];
browserServer = new BrowserServer(launchedProcess, gracefullyClose, connectionType === 'server' ? browserWSEndpoint : null); browserServer = new BrowserServer(launchedProcess, gracefullyClose, launchType === 'server' ? browserWSEndpoint : null);
return { browserServer, transport: connectionType === 'server' ? undefined : new platform.WebSocketTransport(browserWSEndpoint) }; return { browserServer, transport: launchType === 'server' ? undefined : new platform.WebSocketTransport(browserWSEndpoint) };
} }
async connect(options: ConnectOptions): Promise<FFBrowser> { async connect(options: ConnectOptions): Promise<FFBrowser> {
@ -176,7 +176,7 @@ export class Firefox implements BrowserType {
return { TimeoutError }; return { TimeoutError };
} }
private _defaultArgs(options: BrowserArgOptions = {}, userDataDir: string, port: number): string[] { private _defaultArgs(options: BrowserArgOptions = {}, launchType: LaunchType, userDataDir: string, port: number): string[] {
const { const {
devtools = false, devtools = false,
headless = !devtools, headless = !devtools,
@ -189,6 +189,8 @@ export class Firefox implements BrowserType {
throw new Error('Pass userDataDir parameter instead of specifying -profile argument'); throw new Error('Pass userDataDir parameter instead of specifying -profile argument');
if (args.find(arg => arg.startsWith('-juggler'))) if (args.find(arg => arg.startsWith('-juggler')))
throw new Error('Use the port parameter instead of -juggler argument'); throw new Error('Use the port parameter instead of -juggler argument');
if (launchType !== 'persistent' && args.find(arg => !arg.startsWith('-')))
throw new Error('Arguments can not specify page to be opened');
const firefoxArguments = ['-no-remote']; const firefoxArguments = ['-no-remote'];
if (headless) { if (headless) {

View file

@ -181,6 +181,8 @@ export class WebKit implements BrowserType {
const userDataDirArg = args.find(arg => arg.startsWith('--user-data-dir=')); const userDataDirArg = args.find(arg => arg.startsWith('--user-data-dir='));
if (userDataDirArg) if (userDataDirArg)
throw new Error('Pass userDataDir parameter instead of specifying --user-data-dir argument'); throw new Error('Pass userDataDir parameter instead of specifying --user-data-dir argument');
if (launchType !== 'persistent' && args.find(arg => !arg.startsWith('-')))
throw new Error('Arguments can not specify page to be opened');
const webkitArguments = ['--inspector-pipe']; const webkitArguments = ['--inspector-pipe'];
if (headless) if (headless)
webkitArguments.push('--headless'); webkitArguments.push('--headless');

View file

@ -45,6 +45,12 @@ module.exports.describe = function({testRunner, expect, defaultBrowserOptions, p
await playwright.launch(options).catch(e => waitError = e); await playwright.launch(options).catch(e => waitError = e);
expect(waitError.message).toContain('launchPersistent'); expect(waitError.message).toContain('launchPersistent');
}); });
it('should throw if page argument is passed', async() => {
let waitError = null;
const options = Object.assign({}, defaultBrowserOptions, { args: ['http://example.com'] });
await playwright.launch(options).catch(e => waitError = e);
expect(waitError.message).toContain('can not specify page');
});
it('should reject if executable path is invalid', async({server}) => { it('should reject if executable path is invalid', async({server}) => {
let waitError = null; let waitError = null;
const options = Object.assign({}, defaultBrowserOptions, {executablePath: 'random-invalid-path'}); const options = Object.assign({}, defaultBrowserOptions, {executablePath: 'random-invalid-path'});