Skip to content

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

chore: migrate away from ps1 in install-deps on Windows (#9876)

Max Schmitt59a406a586de
diff --git a/packages/playwright-core/bin/install_media_pack.ps1 b/packages/playwright-core/bin/install_media_pack.ps1
deleted file mode 100644
index 6170754291..0000000000
--- a/packages/playwright-core/bin/install_media_pack.ps1
+++ /dev/null
@@ -1,5 +0,0 @@
-$osInfo = Get-WmiObject -Class Win32_OperatingSystem
-# check if running on Windows Server
-if ($osInfo.ProductType -eq 3) {
- Install-WindowsFeature Server-Media-Foundation
-}
diff --git a/packages/playwright-core/src/utils/dependencies.ts b/packages/playwright-core/src/utils/dependencies.ts
index d52e4b6df3..08bf296f49 100644
--- a/packages/playwright-core/src/utils/dependencies.ts
+++ b/packages/playwright-core/src/utils/dependencies.ts
@@ -22,8 +22,6 @@ import { getUbuntuVersion } from './ubuntuVersion';
import * as utils from './utils';
import { buildPlaywrightCLICommand } from './registry';
-const BIN_DIRECTORY = path.join(__dirname, '..', '..', 'bin');
-
const checkExecutable = (filePath: string) => fs.promises.access(filePath, fs.constants.X_OK).then(() => true).catch(e => false);
function isSupportedWindowsVersion(): boolean {
@@ -39,11 +37,33 @@ function isSupportedWindowsVersion(): boolean {
export type DependencyGroup = 'chromium' | 'firefox' | 'webkit' | 'tools';
export async function installDependenciesWindows(targets: Set<DependencyGroup>) {
- if (targets.has('chromium')) {
- const { code } = await utils.spawnAsync('powershell.exe', ['-File', path.join(BIN_DIRECTORY, 'install_media_pack.ps1')], { cwd: BIN_DIRECTORY, stdio: 'inherit' });
- if (code !== 0)
- throw new Error('Failed to install windows dependencies!');
+ if (!targets.has('chromium'))
+ return;
+ if (!await isWindowsServer())
+ return;
+ const { code } = await utils.spawnAsync('dism.exe', ['/Online', '/Enable-Feature', '/FeatureName:ServerMediaFoundation', '/Quiet'], { stdio: 'inherit' });
+ if (code !== 0)
+ throw new Error('Failed to install windows dependencies!');
+}
+
+async function isWindowsServer(): Promise<boolean> {
+ /**
+ * ProductType Enum:
+ * 0 = Unknown - Product type is unknown
+ * 1 = WorkStation - System is a workstation
+ * 2 = DomainController - System is a domain controller
+ * 3 = Server - System is a server
+ * @see https://docs.microsoft.com/en-us/dotnet/api/microsoft.powershell.commands.producttype?view=powershellsdk-1.1.0
+ */
+ const { code, stdout } = await utils.spawnAsync('wmic.exe', ['path', 'Win32_OperatingSystem', 'get', 'ProductType', '/VALUE']);
+ if (code !== 0)
+ throw new Error('Failed to get product type version!');
+ for (const line of stdout.trim().split('\n')) {
+ const [key, value] = line.split('=');
+ if (key === 'ProductType')
+ return parseInt(value, 10) === 3;
}
+ throw new Error('Failed to parse product type version!\nstdout:' + stdout);
}
export async function installDependenciesLinux(targets: Set<DependencyGroup>) {