Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
chore: verify launch options (#2530)
Pavel Feldman17433d1881d2
diff --git a/src/server/browserType.ts b/src/server/browserType.tsindex 4849f32e01..872bf96126 100644--- a/src/server/browserType.ts+++ b/src/server/browserType.ts@@ -53,11 +53,6 @@ export type LaunchOptionsBase = {downloadsPath?: string,};-export function processBrowserArgOptions(options: LaunchOptionsBase): { devtools: boolean, headless: boolean } {- const { devtools = false, headless = !devtools } = options;- return { devtools, headless };-}-type ConnectOptions = {wsEndpoint: string,slowMo?: number,@@ -109,6 +104,7 @@ export abstract class BrowserTypeBase implements BrowserType {async launch(options: LaunchOptions = {}): Promise<Browser> {assert(!(options as any).userDataDir, 'userDataDir option is not supported in `browserType.launch`. Use `browserType.launchPersistentContext` instead');assert(!(options as any).port, 'Cannot specify a port without launching as a server.');+ options = validateLaunchOptions(options);const logger = new InnerLogger(options.logger);const browser = await runAbortableTask(progress => this._innerLaunch(progress, options, logger, undefined), logger, TimeoutSettings.timeout(options));return browser;@@ -116,6 +112,7 @@ export abstract class BrowserTypeBase implements BrowserType {async launchPersistentContext(userDataDir: string, options: LaunchOptions & PersistentContextOptions = {}): Promise<BrowserContext> {assert(!(options as any).port, 'Cannot specify a port without launching as a server.');+ options = validateLaunchOptions(options);const persistent = validateBrowserContextOptions(options);const logger = new InnerLogger(options.logger);const browser = await runAbortableTask(progress => this._innerLaunch(progress, options, logger, persistent, userDataDir), logger, TimeoutSettings.timeout(options));@@ -130,7 +127,7 @@ export abstract class BrowserTypeBase implements BrowserType {const browserOptions: BrowserOptions = {slowMo: options.slowMo,persistent,- headful: !processBrowserArgOptions(options).headless,+ headful: !options.headless,logger,downloadsPath,ownedServer: browserServer,@@ -147,8 +144,9 @@ export abstract class BrowserTypeBase implements BrowserType {async launchServer(options: LaunchServerOptions = {}): Promise<BrowserServer> {assert(!(options as any).userDataDir, 'userDataDir option is not supported in `browserType.launchServer`. Use `browserType.launchPersistentContext` instead');- const { port = 0 } = options;+ options = validateLaunchOptions(options);const logger = new InnerLogger(options.logger);+ const { port = 0 } = options;return runAbortableTask(async progress => {const { browserServer, transport } = await this._launchServer(progress, options, false, logger);browserServer._webSocketServer = this._startWebSocketServer(transport, logger, port);@@ -260,3 +258,8 @@ function copyTestHooks(from: object, to: object) {(to as any)[key] = value;}}++function validateLaunchOptions<Options extends LaunchOptionsBase>(options: Options): Options {+ const { devtools = false, headless = !devtools } = options;+ return { ...options, devtools, headless };+}diff --git a/src/server/chromium.ts b/src/server/chromium.tsindex 29221dba21..0e075e44b7 100644--- a/src/server/chromium.ts+++ b/src/server/chromium.ts@@ -21,7 +21,7 @@ import { CRBrowser } from '../chromium/crBrowser';import * as ws from 'ws';import { Env } from './processLauncher';import { kBrowserCloseMessageId } from '../chromium/crConnection';-import { LaunchOptionsBase, BrowserTypeBase, processBrowserArgOptions } from './browserType';+import { LaunchOptionsBase, BrowserTypeBase } from './browserType';import { ConnectionTransport, ProtocolRequest, ProtocolResponse } from '../transport';import { InnerLogger } from '../logger';import { BrowserDescriptor } from '../install/browserPaths';@@ -78,7 +78,6 @@ export class Chromium extends BrowserTypeBase {}_defaultArgs(options: LaunchOptionsBase, isPersistent: boolean, userDataDir: string): string[] {- const { devtools, headless } = processBrowserArgOptions(options);const { args = [], proxy } = options;const userDataDirArg = args.find(arg => arg.startsWith('--user-data-dir'));if (userDataDirArg)@@ -93,9 +92,9 @@ export class Chromium extends BrowserTypeBase {chromeArguments.push('--remote-debugging-port=' + this._debugPort);elsechromeArguments.push('--remote-debugging-pipe');- if (devtools)+ if (options.devtools)chromeArguments.push('--auto-open-devtools-for-tabs');- if (headless) {+ if (options.headless) {chromeArguments.push('--headless','--hide-scrollbars',diff --git a/src/server/firefox.ts b/src/server/firefox.tsindex 3ae72138e5..8d85dd9250 100644--- a/src/server/firefox.ts+++ b/src/server/firefox.ts@@ -21,7 +21,7 @@ import * as path from 'path';import * as ws from 'ws';import { FFBrowser } from '../firefox/ffBrowser';import { kBrowserCloseMessageId } from '../firefox/ffConnection';-import { LaunchOptionsBase, BrowserTypeBase, processBrowserArgOptions, FirefoxUserPrefsOptions } from './browserType';+import { LaunchOptionsBase, BrowserTypeBase, FirefoxUserPrefsOptions } from './browserType';import { Env } from './processLauncher';import { ConnectionTransport, ProtocolResponse, ProtocolRequest } from '../transport';import { InnerLogger } from '../logger';@@ -57,8 +57,7 @@ export class Firefox extends BrowserTypeBase {}_defaultArgs(options: LaunchOptionsBase & FirefoxUserPrefsOptions, isPersistent: boolean, userDataDir: string): string[] {- const { devtools, headless } = processBrowserArgOptions(options);- const { args = [], proxy } = options;+ const { args = [], proxy, devtools, headless } = options;if (devtools)console.warn('devtools parameter is not supported as a launch argument in Firefox. You can launch the devtools window manually.');const userDataDirArg = args.find(arg => arg.startsWith('-profile') || arg.startsWith('--profile'));diff --git a/src/server/webkit.ts b/src/server/webkit.tsindex dd12561a8a..303a949caf 100644--- a/src/server/webkit.ts+++ b/src/server/webkit.ts@@ -19,7 +19,7 @@ import { WKBrowser } from '../webkit/wkBrowser';import { Env } from './processLauncher';import * as path from 'path';import { kBrowserCloseMessageId } from '../webkit/wkConnection';-import { LaunchOptionsBase, BrowserTypeBase, processBrowserArgOptions } from './browserType';+import { LaunchOptionsBase, BrowserTypeBase } from './browserType';import { ConnectionTransport, ProtocolResponse, ProtocolRequest } from '../transport';import * as ws from 'ws';import { InnerLogger } from '../logger';@@ -50,8 +50,7 @@ export class WebKit extends BrowserTypeBase {}_defaultArgs(options: LaunchOptionsBase, isPersistent: boolean, userDataDir: string): string[] {- const { devtools, headless } = processBrowserArgOptions(options);- const { args = [], proxy } = options;+ const { args = [], proxy, devtools, headless } = options;if (devtools)console.warn('devtools parameter as a launch argument in WebKit is not supported. Also starting Web Inspector manually will terminate the execution in WebKit.');const userDataDirArg = args.find(arg => arg.startsWith('--user-data-dir='));