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: locate binaries in case of cli deployment (#4107)
Pavel Feldman3f68713f1e85
diff --git a/src/server/chromium/videoRecorder.ts b/src/server/chromium/videoRecorder.tsindex b6c4f7e53c..e4f549c9e3 100644--- a/src/server/chromium/videoRecorder.ts+++ b/src/server/chromium/videoRecorder.ts@@ -15,8 +15,7 @@*/import { ChildProcess } from 'child_process';-import * as os from 'os';-import * as path from 'path';+import { ffmpegExecutable } from '../../utils/binaryPaths';import { assert } from '../../utils/utils';import { launchProcess } from '../processLauncher';import { Progress, ProgressController } from '../progress';@@ -59,16 +58,11 @@ export class VideoRecorder {args.push(options.outputFile);const progress = this._progress;- let ffmpegPath = 'ffmpeg';- const binPath = path.join(__dirname, '../../../third_party/ffmpeg/');- if (os.platform() === 'win32')- ffmpegPath = path.join(binPath, os.arch() === 'x64' ? 'ffmpeg-win64.exe' : 'ffmpeg-win32.exe');- else if (os.platform() === 'darwin')- ffmpegPath = path.join(binPath, 'ffmpeg-mac');- else- ffmpegPath = path.join(binPath, 'ffmpeg-linux');+ const executablePath = ffmpegExecutable();+ if (!executablePath)+ throw new Error('ffmpeg executable was not found');const { launchedProcess, gracefullyClose } = await launchProcess({- executablePath: ffmpegPath,+ executablePath,args,pipeStdin: true,progress,diff --git a/src/server/validateDependencies.ts b/src/server/validateDependencies.tsindex 23298ae542..c0d33b81bc 100644--- a/src/server/validateDependencies.ts+++ b/src/server/validateDependencies.ts@@ -20,6 +20,7 @@ import * as os from 'os';import { spawn } from 'child_process';import { getUbuntuVersion } from '../utils/ubuntuVersion';import { linuxLddDirectories, windowsExeAndDllDirectories, BrowserDescriptor } from '../utils/browserPaths.js';+import { printDepsWindowsExecutable } from '../utils/binaryPaths';const accessAsync = util.promisify(fs.access.bind(fs));const checkExecutable = (filePath: string) => accessAsync(filePath, fs.constants.X_OK).then(() => true).catch(e => false);@@ -190,9 +191,12 @@ async function executablesOrSharedLibraries(directoryPath: string): Promise<stri}async function missingFileDependenciesWindows(filePath: string): Promise<Array<string>> {+ const executable = printDepsWindowsExecutable();+ if (!executable)+ return [];+const dirname = path.dirname(filePath);- const printDepsWindowsExecutable = process.env.PW_PRINT_DEPS_WINDOWS_EXECUTABLE || path.join(__dirname, '../../bin/PrintDeps.exe');- const {stdout, code} = await spawnAsync(printDepsWindowsExecutable, [filePath], {+ const {stdout, code} = await spawnAsync(executable, [filePath], {cwd: dirname,env: {...process.env,diff --git a/src/utils/binaryPaths.ts b/src/utils/binaryPaths.tsnew file mode 100644index 0000000000..7542e5d7e6--- /dev/null+++ b/src/utils/binaryPaths.ts@@ -0,0 +1,51 @@+/**+ * Copyright (c) Microsoft Corporation.+ *+ * 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 * as fs from 'fs';+import * as os from 'os';+import * as path from 'path';++export function printDepsWindowsExecutable(): string | undefined {+ return pathToExecutable(['bin', 'PrintDeps.exe']);+}++export function ffmpegExecutable(): string | undefined {+ let ffmpegName;+ if (process.platform === 'win32')+ ffmpegName = os.arch() === 'x64' ? 'ffmpeg-win64.exe' : 'ffmpeg-win32.exe';+ else if (process.platform === 'darwin')+ ffmpegName = 'ffmpeg-mac';+ else+ ffmpegName = 'ffmpeg-linux';+ return pathToExecutable(['third_party', 'ffmpeg', ffmpegName]);+}++function pathToExecutable(relative: string[]): string | undefined {+ const defaultPath = path.join(__dirname, '..', '..', ...relative);+ const localPath = path.join(path.dirname(process.argv[0]), relative[relative.length - 1]);+ try {+ if (fs.existsSync(defaultPath))+ return defaultPath;+ } catch (e) {+ }++ try {+ if (fs.existsSync(localPath))+ return localPath;+ } catch (e) {+ }+}+