Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

chore: add missing dynamic sdkLanguage based CLI invocations (#9817)

Max Schmittbe64b5f6e2c0
diff --git a/packages/playwright-core/src/server/browserType.ts b/packages/playwright-core/src/server/browserType.ts
index fc613597c3..69cb412f1d 100644
--- a/packages/playwright-core/src/server/browserType.ts
+++ b/packages/playwright-core/src/server/browserType.ts
@@ -45,7 +45,7 @@ export abstract class BrowserType extends SdkObject {
}
executablePath(): string {
- return registry.findExecutable(this._name).executablePath() || '';
+ return registry.findExecutable(this._name).executablePath(this._playwrightOptions.sdkLanguage) || '';
}
name(): string {
@@ -173,7 +173,7 @@ export abstract class BrowserType extends SdkObject {
if (!registryExecutable || registryExecutable.browserName !== this._name)
throw new Error(`Unsupported ${this._name} channel "${options.channel}"`);
executable = registryExecutable.executablePathOrDie(this._playwrightOptions.sdkLanguage);
- await registryExecutable.validateHostRequirements();
+ await registryExecutable.validateHostRequirements(this._playwrightOptions.sdkLanguage);
}
let wsEndpointCallback: ((wsEndpoint: string) => void) | undefined;
diff --git a/packages/playwright-core/src/utils/dependencies.ts b/packages/playwright-core/src/utils/dependencies.ts
index 299b39ec02..d52e4b6df3 100644
--- a/packages/playwright-core/src/utils/dependencies.ts
+++ b/packages/playwright-core/src/utils/dependencies.ts
@@ -20,6 +20,7 @@ import * as os from 'os';
import childProcess from 'child_process';
import { getUbuntuVersion } from './ubuntuVersion';
import * as utils from './utils';
+import { buildPlaywrightCLICommand } from './registry';
const BIN_DIRECTORY = path.join(__dirname, '..', '..', 'bin');
@@ -148,7 +149,7 @@ export async function validateDependenciesWindows(windowsExeAndDllDirectories: s
}
}
-export async function validateDependenciesLinux(linuxLddDirectories: string[], dlOpenLibraries: string[]) {
+export async function validateDependenciesLinux(sdkLanguage: string, linuxLddDirectories: string[], dlOpenLibraries: string[]) {
const directoryPaths = linuxLddDirectories;
const lddPaths: string[] = [];
for (const directoryPath of directoryPaths)
@@ -194,7 +195,7 @@ export async function validateDependenciesLinux(linuxLddDirectories: string[], d
`Host system is missing a few dependencies to run browsers.`,
`Please install them with the following command:`,
``,
- ` ${maybeSudo}npx playwright install-deps`,
+ ` ${maybeSudo}${buildPlaywrightCLICommand(sdkLanguage, 'install-deps')}`,
``,
`<3 Playwright Team`,
].join('\n'), 1));
diff --git a/packages/playwright-core/src/utils/registry.ts b/packages/playwright-core/src/utils/registry.ts
index 03733db58b..36ba8a76ce 100644
--- a/packages/playwright-core/src/utils/registry.ts
+++ b/packages/playwright-core/src/utils/registry.ts
@@ -235,8 +235,8 @@ export interface Executable {
installType: 'download-by-default' | 'download-on-demand' | 'install-script' | 'none';
directory: string | undefined;
executablePathOrDie(sdkLanguage: string): string;
- executablePath(): string | undefined;
- validateHostRequirements(): Promise<void>;
+ executablePath(sdkLanguage: string): string | undefined;
+ validateHostRequirements(sdkLanguage: string): Promise<void>;
}
interface ExecutableImpl extends Executable {
@@ -282,7 +282,7 @@ export class Registry {
executablePath: () => chromiumExecutable,
executablePathOrDie: (sdkLanguage: string) => executablePathOrDie('chromium', chromiumExecutable, chromium.installByDefault, sdkLanguage),
installType: chromium.installByDefault ? 'download-by-default' : 'download-on-demand',
- validateHostRequirements: () => this._validateHostRequirements('chromium', chromium.dir, ['chrome-linux'], [], ['chrome-win']),
+ validateHostRequirements: (sdkLanguage: string) => this._validateHostRequirements(sdkLanguage, 'chromium', chromium.dir, ['chrome-linux'], [], ['chrome-win']),
_install: () => this._downloadExecutable(chromium, chromiumExecutable, DOWNLOAD_URLS['chromium'][hostPlatform], 'PLAYWRIGHT_CHROMIUM_DOWNLOAD_HOST'),
_dependencyGroup: 'chromium',
});
@@ -297,7 +297,7 @@ export class Registry {
executablePath: () => chromiumWithSymbolsExecutable,
executablePathOrDie: (sdkLanguage: string) => executablePathOrDie('chromium-with-symbols', chromiumWithSymbolsExecutable, chromiumWithSymbols.installByDefault, sdkLanguage),
installType: chromiumWithSymbols.installByDefault ? 'download-by-default' : 'download-on-demand',
- validateHostRequirements: () => this._validateHostRequirements('chromium', chromiumWithSymbols.dir, ['chrome-linux'], [], ['chrome-win']),
+ validateHostRequirements: (sdkLanguage: string) => this._validateHostRequirements(sdkLanguage, 'chromium', chromiumWithSymbols.dir, ['chrome-linux'], [], ['chrome-win']),
_install: () => this._downloadExecutable(chromiumWithSymbols, chromiumWithSymbolsExecutable, DOWNLOAD_URLS['chromium-with-symbols'][hostPlatform], 'PLAYWRIGHT_CHROMIUM_DOWNLOAD_HOST'),
_dependencyGroup: 'chromium',
});
@@ -380,7 +380,7 @@ export class Registry {
executablePath: () => firefoxExecutable,
executablePathOrDie: (sdkLanguage: string) => executablePathOrDie('firefox', firefoxExecutable, firefox.installByDefault, sdkLanguage),
installType: firefox.installByDefault ? 'download-by-default' : 'download-on-demand',
- validateHostRequirements: () => this._validateHostRequirements('firefox', firefox.dir, ['firefox'], [], ['firefox']),
+ validateHostRequirements: (sdkLanguage: string) => this._validateHostRequirements(sdkLanguage, 'firefox', firefox.dir, ['firefox'], [], ['firefox']),
_install: () => this._downloadExecutable(firefox, firefoxExecutable, DOWNLOAD_URLS['firefox'][hostPlatform], 'PLAYWRIGHT_FIREFOX_DOWNLOAD_HOST'),
_dependencyGroup: 'firefox',
});
@@ -395,7 +395,7 @@ export class Registry {
executablePath: () => firefoxBetaExecutable,
executablePathOrDie: (sdkLanguage: string) => executablePathOrDie('firefox-beta', firefoxBetaExecutable, firefoxBeta.installByDefault, sdkLanguage),
installType: firefoxBeta.installByDefault ? 'download-by-default' : 'download-on-demand',
- validateHostRequirements: () => this._validateHostRequirements('firefox', firefoxBeta.dir, ['firefox'], [], ['firefox']),
+ validateHostRequirements: (sdkLanguage: string) => this._validateHostRequirements(sdkLanguage, 'firefox', firefoxBeta.dir, ['firefox'], [], ['firefox']),
_install: () => this._downloadExecutable(firefoxBeta, firefoxBetaExecutable, DOWNLOAD_URLS['firefox-beta'][hostPlatform], 'PLAYWRIGHT_FIREFOX_DOWNLOAD_HOST'),
_dependencyGroup: 'firefox',
});
@@ -418,7 +418,7 @@ export class Registry {
executablePath: () => webkitExecutable,
executablePathOrDie: (sdkLanguage: string) => executablePathOrDie('webkit', webkitExecutable, webkit.installByDefault, sdkLanguage),
installType: webkit.installByDefault ? 'download-by-default' : 'download-on-demand',
- validateHostRequirements: () => this._validateHostRequirements('webkit', webkit.dir, webkitLinuxLddDirectories, ['libGLESv2.so.2', 'libx264.so'], ['']),
+ validateHostRequirements: (sdkLanguage: string) => this._validateHostRequirements(sdkLanguage, 'webkit', webkit.dir, webkitLinuxLddDirectories, ['libGLESv2.so.2', 'libx264.so'], ['']),
_install: () => this._downloadExecutable(webkit, webkitExecutable, DOWNLOAD_URLS['webkit'][hostPlatform], 'PLAYWRIGHT_WEBKIT_DOWNLOAD_HOST'),
_dependencyGroup: 'webkit',
});
@@ -440,7 +440,7 @@ export class Registry {
}
private _createChromiumChannel(name: ChromiumChannel, lookAt: Record<'linux' | 'darwin' | 'win32', string>, install?: () => Promise<void>): ExecutableImpl {
- const executablePath = (shouldThrow: boolean) => {
+ const executablePath = (sdkLanguage: string, shouldThrow: boolean) => {
const suffix = lookAt[process.platform as 'linux' | 'darwin' | 'win32'];
if (!suffix) {
if (shouldThrow)
@@ -461,7 +461,7 @@ export class Registry {
const location = prefixes.length ? ` at ${path.join(prefixes[0], suffix)}` : ``;
// TODO: language-specific error message
- const installation = install ? `\nRun "npx playwright install ${name}"` : '';
+ const installation = install ? `\nRun "${buildPlaywrightCLICommand(sdkLanguage, 'install ' + name)}"` : '';
throw new Error(`Chromium distribution '${name}' is not found${location}${installation}`);
};
return {
@@ -469,8 +469,8 @@ export class Registry {
name,
browserName: 'chromium',
directory: undefined,
- executablePath: () => executablePath(false),
- executablePathOrDie: (sdkLanguage: string) => executablePath(true)!,
+ executablePath: (sdkLanguage: string) => executablePath(sdkLanguage, false),
+ executablePathOrDie: (sdkLanguage: string) => executablePath(sdkLanguage, true)!,
installType: install ? 'install-script' : 'none',
validateHostRequirements: () => Promise.resolve(),
_install: install,
@@ -501,7 +501,7 @@ export class Registry {
return Array.from(set);
}
- private async _validateHostRequirements(browserName: BrowserName, browserDirectory: string, linuxLddDirectories: string[], dlOpenLibraries: string[], windowsExeAndDllDirectories: string[]) {
+ private async _validateHostRequirements(sdkLanguage: string, browserName: BrowserName, browserDirectory: string, linuxLddDirectories: string[], dlOpenLibraries: string[], windowsExeAndDllDirectories: string[]) {
if (getAsBooleanFromENV('PLAYWRIGHT_SKIP_VALIDATE_HOST_REQUIREMENTS')) {
process.stdout.write('Skipping host requirements validation logic because `PLAYWRIGHT_SKIP_VALIDATE_HOST_REQUIREMENTS` env variable is set.\n');
return;
@@ -511,7 +511,7 @@ export class Registry {
throw new Error(`Cannot launch Firefox on Ubuntu 16.04! Minimum required Ubuntu version for Firefox browser is 18.04`);
if (os.platform() === 'linux')
- return await validateDependenciesLinux(linuxLddDirectories.map(d => path.join(browserDirectory, d)), dlOpenLibraries);
+ return await validateDependenciesLinux(sdkLanguage, linuxLddDirectories.map(d => path.join(browserDirectory, d)), dlOpenLibraries);
if (os.platform() === 'win32' && os.arch() === 'x64')
return await validateDependenciesWindows(windowsExeAndDllDirectories.map(d => path.join(browserDirectory, d)));
}
@@ -697,7 +697,7 @@ function markerFilePath(browserDirectory: string): string {
return path.join(browserDirectory, 'INSTALLATION_COMPLETE');
}
-function buildPlaywrightCLICommand(sdkLanguage: string, parameters: string): string {
+export function buildPlaywrightCLICommand(sdkLanguage: string, parameters: string): string {
switch (sdkLanguage) {
case 'python':
return `playwright ${parameters}`;
diff --git a/tests/video.spec.ts b/tests/video.spec.ts
index bad15239a5..eb9492db46 100644
--- a/tests/video.spec.ts
+++ b/tests/video.spec.ts
@@ -21,7 +21,7 @@ import { spawnSync } from 'child_process';
import { PNG } from 'pngjs';
import { registry } from 'playwright-core/lib/utils/registry';
-const ffmpeg = registry.findExecutable('ffmpeg')!.executablePath();
+const ffmpeg = registry.findExecutable('ffmpeg')!.executablePath('javascript');
export class VideoPlayer {
fileName: string;