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: better Electron error message when no executable path is given (#13318)
Max Schmitt844ecbe2eb49
diff --git a/packages/playwright-core/src/server/electron/electron.ts b/packages/playwright-core/src/server/electron/electron.tsindex 35d4c49ff9..8b6dac8822 100644--- a/packages/playwright-core/src/server/electron/electron.ts+++ b/packages/playwright-core/src/server/electron/electron.ts@@ -24,6 +24,7 @@ import { CRExecutionContext } from '../chromium/crExecutionContext';import * as js from '../javascript';import { Page } from '../page';import { TimeoutSettings } from '../../utils/timeoutSettings';+import { wrapInASCIIBox } from '../../utils/utils';import { WebSocketTransport } from '../transport';import { launchProcess, envArrayToObject } from '../../utils/processLauncher';import { BrowserContext, validateBrowserContextOptions } from '../browserContext';@@ -134,12 +135,32 @@ export class Electron extends SdkObject {const browserLogsCollector = new RecentLogsCollector();const env = options.env ? envArrayToObject(options.env) : process.env;++ let command: string;+ if (options.executablePath) {+ command = options.executablePath;+ } else {+ try {+ // By default we fallback to the Electron App executable path.+ // 'electron/index.js' resolves to the actual Electron App.+ command = require('electron/index.js');+ } catch (error: any) {+ if ((error as NodeJS.ErrnoException)?.code === 'MODULE_NOT_FOUND') {+ throw new Error('\n' + wrapInASCIIBox([+ 'Electron executablePath not found!',+ 'Please install it using `npm install -D electron` or set the executablePath to your Electron executable.',+ ].join('\n'), 1));+ }+ throw error;+ }+ }+// When debugging Playwright test that runs Electron, NODE_OPTIONS// will make the debugger attach to Electron's Node. But Playwright// also needs to attach to drive the automation. Disable external debugging.delete env.NODE_OPTIONS;const { launchedProcess, gracefullyClose, kill } = await launchProcess({- command: options.executablePath || require('electron/index.js'),+ command,args: electronArguments,env,log: (message: string) => {