mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
feat: allow to pick stable channel (#5817)
This commit is contained in:
parent
0d32b0538c
commit
a96d6a7dbb
2
.github/workflows/tests.yml
vendored
2
.github/workflows/tests.yml
vendored
@ -283,7 +283,7 @@ jobs:
|
|||||||
- run: xvfb-run --auto-servernum --server-args="-screen 0 1280x960x24" -- bash -c "ulimit -c unlimited && npx folio test/ --workers=1 --forbid-only --timeout=60000 --global-timeout=5400000 --retries=3 --reporter=dot,json -p video"
|
- run: xvfb-run --auto-servernum --server-args="-screen 0 1280x960x24" -- bash -c "ulimit -c unlimited && npx folio test/ --workers=1 --forbid-only --timeout=60000 --global-timeout=5400000 --retries=3 --reporter=dot,json -p video"
|
||||||
env:
|
env:
|
||||||
BROWSER: "chromium"
|
BROWSER: "chromium"
|
||||||
CRPATH: "/opt/google/chrome/chrome"
|
PW_CHROMIUM_CHANNEL: "chrome"
|
||||||
FOLIO_JSON_OUTPUT_NAME: "test-results/report.json"
|
FOLIO_JSON_OUTPUT_NAME: "test-results/report.json"
|
||||||
- uses: actions/upload-artifact@v1
|
- uses: actions/upload-artifact@v1
|
||||||
if: ${{ always() }}
|
if: ${{ always() }}
|
||||||
|
@ -178,6 +178,19 @@ Whether to run browser in headless mode. More details for
|
|||||||
[Firefox](https://developer.mozilla.org/en-US/docs/Mozilla/Firefox/Headless_mode). Defaults to `true` unless the
|
[Firefox](https://developer.mozilla.org/en-US/docs/Mozilla/Firefox/Headless_mode). Defaults to `true` unless the
|
||||||
[`option: devtools`] option is `true`.
|
[`option: devtools`] option is `true`.
|
||||||
|
|
||||||
|
### option: BrowserType.launch.channel
|
||||||
|
- `channel` <[string]>
|
||||||
|
|
||||||
|
Chromium distribution channel, one of
|
||||||
|
* chrome
|
||||||
|
* chrome-beta
|
||||||
|
* chrome-dev
|
||||||
|
* chrome-canary
|
||||||
|
* msedge
|
||||||
|
* msedge-beta
|
||||||
|
* msedge-dev
|
||||||
|
* msedge-canary
|
||||||
|
|
||||||
### option: BrowserType.launch.executablePath
|
### option: BrowserType.launch.executablePath
|
||||||
- `executablePath` <[path]>
|
- `executablePath` <[path]>
|
||||||
|
|
||||||
|
@ -103,12 +103,12 @@ program
|
|||||||
|
|
||||||
program
|
program
|
||||||
.command('install-deps [browserType...]')
|
.command('install-deps [browserType...]')
|
||||||
.description('install dependencies necessary to run browser')
|
.description('install dependencies necessary to run browsers (will ask for sudo permissions)')
|
||||||
.action(async function(browserType) {
|
.action(async function(browserType) {
|
||||||
try {
|
try {
|
||||||
await installDeps(browserType);
|
await installDeps(browserType);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(`Failed to install browsers\n${e}`);
|
console.log(`Failed to install browser dependencies\n${e}`);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -82,7 +82,7 @@ export class Connection {
|
|||||||
return await new Promise((resolve, reject) => this._callbacks.set(id, { resolve, reject }));
|
return await new Promise((resolve, reject) => this._callbacks.set(id, { resolve, reject }));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const innerStack = ((process.env.PWDEBUGIMPL || isUnderTest()) && e.stack) ? e.stack.substring(e.stack.indexOf(e.message) + e.message.length) : '';
|
const innerStack = ((process.env.PWDEBUGIMPL || isUnderTest()) && e.stack) ? e.stack.substring(e.stack.indexOf(e.message) + e.message.length) : '';
|
||||||
e.stack = e.message + innerStack + stack;
|
e.stack = e.message + innerStack + '\n' + stack;
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -217,6 +217,7 @@ export interface BrowserTypeChannel extends Channel {
|
|||||||
connectOverCDP(params: BrowserTypeConnectOverCDPParams, metadata?: Metadata): Promise<BrowserTypeConnectOverCDPResult>;
|
connectOverCDP(params: BrowserTypeConnectOverCDPParams, metadata?: Metadata): Promise<BrowserTypeConnectOverCDPResult>;
|
||||||
}
|
}
|
||||||
export type BrowserTypeLaunchParams = {
|
export type BrowserTypeLaunchParams = {
|
||||||
|
channel?: string,
|
||||||
executablePath?: string,
|
executablePath?: string,
|
||||||
args?: string[],
|
args?: string[],
|
||||||
ignoreAllDefaultArgs?: boolean,
|
ignoreAllDefaultArgs?: boolean,
|
||||||
@ -240,6 +241,7 @@ export type BrowserTypeLaunchParams = {
|
|||||||
slowMo?: number,
|
slowMo?: number,
|
||||||
};
|
};
|
||||||
export type BrowserTypeLaunchOptions = {
|
export type BrowserTypeLaunchOptions = {
|
||||||
|
channel?: string,
|
||||||
executablePath?: string,
|
executablePath?: string,
|
||||||
args?: string[],
|
args?: string[],
|
||||||
ignoreAllDefaultArgs?: boolean,
|
ignoreAllDefaultArgs?: boolean,
|
||||||
|
@ -300,6 +300,7 @@ BrowserType:
|
|||||||
|
|
||||||
launch:
|
launch:
|
||||||
parameters:
|
parameters:
|
||||||
|
channel: string?
|
||||||
executablePath: string?
|
executablePath: string?
|
||||||
args:
|
args:
|
||||||
type: array?
|
type: array?
|
||||||
|
@ -154,6 +154,7 @@ export function createScheme(tChannel: (name: string) => Validator): Scheme {
|
|||||||
contentScript: tOptional(tBoolean),
|
contentScript: tOptional(tBoolean),
|
||||||
});
|
});
|
||||||
scheme.BrowserTypeLaunchParams = tObject({
|
scheme.BrowserTypeLaunchParams = tObject({
|
||||||
|
channel: tOptional(tString),
|
||||||
executablePath: tOptional(tString),
|
executablePath: tOptional(tString),
|
||||||
args: tOptional(tArray(tString)),
|
args: tOptional(tArray(tString)),
|
||||||
ignoreAllDefaultArgs: tOptional(tBoolean),
|
ignoreAllDefaultArgs: tOptional(tBoolean),
|
||||||
|
@ -51,7 +51,7 @@ export abstract class BrowserType extends SdkObject {
|
|||||||
this._registry = playwrightOptions.registry;
|
this._registry = playwrightOptions.registry;
|
||||||
}
|
}
|
||||||
|
|
||||||
executablePath(): string {
|
executablePath(options?: types.LaunchOptions): string {
|
||||||
return this._registry.executablePath(this._name) || '';
|
return this._registry.executablePath(this._name) || '';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -165,7 +165,7 @@ export abstract class BrowserType extends SdkObject {
|
|||||||
else
|
else
|
||||||
browserArguments.push(...this._defaultArgs(options, isPersistent, userDataDir));
|
browserArguments.push(...this._defaultArgs(options, isPersistent, userDataDir));
|
||||||
|
|
||||||
const executable = executablePath || this.executablePath();
|
const executable = executablePath || this.executablePath(options);
|
||||||
if (!executable)
|
if (!executable)
|
||||||
throw new Error(`No executable path is specified. Pass "executablePath" option directly.`);
|
throw new Error(`No executable path is specified. Pass "executablePath" option directly.`);
|
||||||
if (!(await existsAsync(executable))) {
|
if (!(await existsAsync(executable))) {
|
||||||
|
@ -31,6 +31,7 @@ import { ProgressController } from '../progress';
|
|||||||
import { TimeoutSettings } from '../../utils/timeoutSettings';
|
import { TimeoutSettings } from '../../utils/timeoutSettings';
|
||||||
import { helper } from '../helper';
|
import { helper } from '../helper';
|
||||||
import { CallMetadata } from '../instrumentation';
|
import { CallMetadata } from '../instrumentation';
|
||||||
|
import { findChromiumChannel } from './findChromiumChannel';
|
||||||
|
|
||||||
export class Chromium extends BrowserType {
|
export class Chromium extends BrowserType {
|
||||||
private _devtools: CRDevTools | undefined;
|
private _devtools: CRDevTools | undefined;
|
||||||
@ -42,6 +43,12 @@ export class Chromium extends BrowserType {
|
|||||||
this._devtools = this._createDevTools();
|
this._devtools = this._createDevTools();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
executablePath(options?: types.LaunchOptions): string {
|
||||||
|
if (options?.channel)
|
||||||
|
return findChromiumChannel(options.channel);
|
||||||
|
return super.executablePath(options);
|
||||||
|
}
|
||||||
|
|
||||||
async connectOverCDP(metadata: CallMetadata, wsEndpoint: string, options: { slowMo?: number, sdkLanguage: string }, timeout?: number) {
|
async connectOverCDP(metadata: CallMetadata, wsEndpoint: string, options: { slowMo?: number, sdkLanguage: string }, timeout?: number) {
|
||||||
const controller = new ProgressController(metadata, this);
|
const controller = new ProgressController(metadata, this);
|
||||||
controller.setLogName('browser');
|
controller.setLogName('browser');
|
||||||
|
92
src/server/chromium/findChromiumChannel.ts
Normal file
92
src/server/chromium/findChromiumChannel.ts
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the 'License');
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an 'AS IS' BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import fs from 'fs';
|
||||||
|
import path from 'path';
|
||||||
|
|
||||||
|
function darwin(channel: string): string | undefined {
|
||||||
|
switch (channel) {
|
||||||
|
case 'chrome': return '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome';
|
||||||
|
case 'chrome-canary': return '/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary';
|
||||||
|
case 'msedge': return '/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge';
|
||||||
|
case 'msedge-beta': return '/Applications/Microsoft Edge Beta.app/Contents/MacOS/Microsoft Edge Beta';
|
||||||
|
case 'msedge-dev': return '/Applications/Microsoft Edge Dev.app/Contents/MacOS/Microsoft Edge Dev';
|
||||||
|
case 'msedge-canary': return '/Applications/Microsoft Edge Canary.app/Contents/MacOS/Microsoft Edge Canary';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function linux(channel: string): string | undefined {
|
||||||
|
switch (channel) {
|
||||||
|
case 'chrome': return '/opt/google/chrome/chrome';
|
||||||
|
case 'chrome-beta': return '/opt/google/chrome-beta/chrome';
|
||||||
|
case 'chrome-dev': return '/opt/google/chrome-unstable/chrome';
|
||||||
|
case 'msedge-dev': return '/opt/microsoft/msedge-dev/msedge';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function win32(channel: string): string | undefined {
|
||||||
|
let suffix: string | undefined;
|
||||||
|
switch (channel) {
|
||||||
|
case 'chrome': suffix = `\\Google\\Chrome\\Application\\chrome.exe`; break;
|
||||||
|
case 'chrome-canary': suffix = `\\Google\\Chrome SxS\\Application\\chrome.exe`; break;
|
||||||
|
case 'msedge': suffix = `\\Microsoft\\Edge\\Application\\msedge.exe`; break;
|
||||||
|
case 'msedge-beta': suffix = `\\Microsoft\\Edge Beta\\Application\\msedge.exe`; break;
|
||||||
|
case 'msedge-dev': suffix = `\\Microsoft\\Edge Dev\\Application\\msedge.exe`; break;
|
||||||
|
case 'msedge-canary': suffix = `\\Microsoft\\Edge SxS\\Application\\msedge.exe`; break;
|
||||||
|
}
|
||||||
|
if (!suffix)
|
||||||
|
return;
|
||||||
|
const prefixes = [
|
||||||
|
process.env.LOCALAPPDATA, process.env.PROGRAMFILES, process.env['PROGRAMFILES(X86)']
|
||||||
|
].filter(Boolean) as string[];
|
||||||
|
|
||||||
|
let result: string | undefined;
|
||||||
|
prefixes.forEach(prefix => {
|
||||||
|
const chromePath = path.join(prefix, suffix!);
|
||||||
|
if (canAccess(chromePath))
|
||||||
|
result = chromePath;
|
||||||
|
});
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
function canAccess(file: string) {
|
||||||
|
if (!file)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
try {
|
||||||
|
fs.accessSync(file);
|
||||||
|
return true;
|
||||||
|
} catch (e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function findChromiumChannel(channel: string): string {
|
||||||
|
let result: string | undefined;
|
||||||
|
if (process.platform === 'linux')
|
||||||
|
result = linux(channel);
|
||||||
|
else if (process.platform === 'win32')
|
||||||
|
result = win32(channel);
|
||||||
|
else if (process.platform === 'darwin')
|
||||||
|
result = darwin(channel);
|
||||||
|
|
||||||
|
if (!result)
|
||||||
|
throw new Error(`Chromium distribution '${channel}' is not supported on ${process.platform}`);
|
||||||
|
|
||||||
|
if (canAccess(result))
|
||||||
|
return result;
|
||||||
|
throw new Error(`Chromium distribution was not found: ${channel}`);
|
||||||
|
}
|
@ -250,6 +250,7 @@ export type BrowserContextOptions = {
|
|||||||
export type EnvArray = { name: string, value: string }[];
|
export type EnvArray = { name: string, value: string }[];
|
||||||
|
|
||||||
type LaunchOptionsBase = {
|
type LaunchOptionsBase = {
|
||||||
|
channel?: string,
|
||||||
executablePath?: string,
|
executablePath?: string,
|
||||||
args?: string[],
|
args?: string[],
|
||||||
ignoreDefaultArgs?: string[],
|
ignoreDefaultArgs?: string[],
|
||||||
|
@ -92,6 +92,7 @@ fixtures.browserOptions.override(async ({ browserName, headful, slowMo }, run) =
|
|||||||
if (executablePath)
|
if (executablePath)
|
||||||
console.error(`Using executable at ${executablePath}`);
|
console.error(`Using executable at ${executablePath}`);
|
||||||
await run({
|
await run({
|
||||||
|
channel: process.env.PW_CHROMIUM_CHANNEL,
|
||||||
executablePath,
|
executablePath,
|
||||||
handleSIGINT: false,
|
handleSIGINT: false,
|
||||||
slowMo,
|
slowMo,
|
||||||
|
13
types/types.d.ts
vendored
13
types/types.d.ts
vendored
@ -10645,6 +10645,19 @@ export interface LaunchOptions {
|
|||||||
*/
|
*/
|
||||||
args?: Array<string>;
|
args?: Array<string>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Chromium distribution channel, one of
|
||||||
|
* - chrome
|
||||||
|
* - chrome-beta
|
||||||
|
* - chrome-dev
|
||||||
|
* - chrome-canary
|
||||||
|
* - msedge
|
||||||
|
* - msedge-beta
|
||||||
|
* - msedge-dev
|
||||||
|
* - msedge-canary
|
||||||
|
*/
|
||||||
|
channel?: string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enable Chromium sandboxing. Defaults to `false`.
|
* Enable Chromium sandboxing. Defaults to `false`.
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user