Skip to content

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

chore(electron): keep package internal, restore _electron on playwright (#40461)

Dmitry Gozman5d47c8eb1b99
diff --git a/package-lock.json b/package-lock.json
index 3abad98229..3253454491 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -9752,10 +9752,10 @@
},
"packages/playwright-electron": {
"name": "@playwright/electron",
- "version": "1.60.0-next",
+ "version": "0.0.0",
"license": "Apache-2.0",
"dependencies": {
- "playwright": "1.60.0-next"
+ "playwright": "*"
},
"engines": {
"node": ">=18"
diff --git a/packages/playwright-client/types/types.d.ts b/packages/playwright-client/types/types.d.ts
index 05fb9e1ed8..d36153bd9f 100644
--- a/packages/playwright-client/types/types.d.ts
+++ b/packages/playwright-client/types/types.d.ts
@@ -16858,6 +16858,323 @@ export type AndroidKey =
export const _android: Android;
+//@ts-ignore this will be any if electron is not installed
+type ElectronType = typeof import('electron');
+
+/**
+ * Electron application representation. You can use
+ * [electron.launch([options])](https://playwright.dev/docs/api/class-electron#electron-launch) to obtain the
+ * application instance. This instance you can control main electron process as well as work with Electron windows:
+ *
+ * ```js
+ * const { _electron: electron } = require('playwright');
+ *
+ * (async () => {
+ * // Launch Electron app.
+ * const electronApp = await electron.launch({ args: ['main.js'] });
+ *
+ * // Evaluation expression in the Electron context.
+ * const appPath = await electronApp.evaluate(async ({ app }) => {
+ * // This runs in the main Electron process, parameter here is always
+ * // the result of the require('electron') in the main app script.
+ * return app.getAppPath();
+ * });
+ * console.log(appPath);
+ *
+ * // Get the first window that the app opens, wait if necessary.
+ * const window = await electronApp.firstWindow();
+ * // Print the title.
+ * console.log(await window.title());
+ * // Capture a screenshot.
+ * await window.screenshot({ path: 'intro.png' });
+ * // Direct Electron console to Node terminal.
+ * window.on('console', console.log);
+ * // Click button.
+ * await window.click('text=Click me');
+ * // Exit app.
+ * await electronApp.close();
+ * })();
+ * ```
+ *
+ */
+export interface ElectronApplication {
+ /**
+ * Returns the return value of
+ * [`pageFunction`](https://playwright.dev/docs/api/class-electronapplication#electron-application-evaluate-option-expression).
+ *
+ * If the function passed to the
+ * [electronApplication.evaluate(pageFunction[, arg])](https://playwright.dev/docs/api/class-electronapplication#electron-application-evaluate)
+ * returns a [Promise], then
+ * [electronApplication.evaluate(pageFunction[, arg])](https://playwright.dev/docs/api/class-electronapplication#electron-application-evaluate)
+ * would wait for the promise to resolve and return its value.
+ *
+ * If the function passed to the
+ * [electronApplication.evaluate(pageFunction[, arg])](https://playwright.dev/docs/api/class-electronapplication#electron-application-evaluate)
+ * returns a non-[Serializable] value, then
+ * [electronApplication.evaluate(pageFunction[, arg])](https://playwright.dev/docs/api/class-electronapplication#electron-application-evaluate)
+ * returns `undefined`. Playwright also supports transferring some additional values that are not serializable by
+ * `JSON`: `-0`, `NaN`, `Infinity`, `-Infinity`.
+ * @param pageFunction Function to be evaluated in the main Electron process.
+ * @param arg Optional argument to pass to
+ * [`pageFunction`](https://playwright.dev/docs/api/class-electronapplication#electron-application-evaluate-option-expression).
+ */
+ evaluate: JSHandle<ElectronType>['evaluate'];
+ /**
+ * Returns the return value of
+ * [`pageFunction`](https://playwright.dev/docs/api/class-electronapplication#electron-application-evaluate-handle-option-expression)
+ * as a [JSHandle](https://playwright.dev/docs/api/class-jshandle).
+ *
+ * The only difference between
+ * [electronApplication.evaluate(pageFunction[, arg])](https://playwright.dev/docs/api/class-electronapplication#electron-application-evaluate)
+ * and
+ * [electronApplication.evaluateHandle(pageFunction[, arg])](https://playwright.dev/docs/api/class-electronapplication#electron-application-evaluate-handle)
+ * is that
+ * [electronApplication.evaluateHandle(pageFunction[, arg])](https://playwright.dev/docs/api/class-electronapplication#electron-application-evaluate-handle)
+ * returns [JSHandle](https://playwright.dev/docs/api/class-jshandle).
+ *
+ * If the function passed to the
+ * [electronApplication.evaluateHandle(pageFunction[, arg])](https://playwright.dev/docs/api/class-electronapplication#electron-application-evaluate-handle)
+ * returns a [Promise], then
+ * [electronApplication.evaluateHandle(pageFunction[, arg])](https://playwright.dev/docs/api/class-electronapplication#electron-application-evaluate-handle)
+ * would wait for the promise to resolve and return its value.
+ * @param pageFunction Function to be evaluated in the main Electron process.
+ * @param arg Optional argument to pass to
+ * [`pageFunction`](https://playwright.dev/docs/api/class-electronapplication#electron-application-evaluate-handle-option-expression).
+ */
+ evaluateHandle: JSHandle<ElectronType>['evaluateHandle'];
+ /**
+ * This event is issued when the application process has been terminated.
+ */
+ on(event: 'close', listener: () => any): this;
+
+ /**
+ * Emitted when JavaScript within the Electron main process calls one of console API methods, e.g. `console.log` or
+ * `console.dir`.
+ *
+ * The arguments passed into `console.log` are available on the
+ * [ConsoleMessage](https://playwright.dev/docs/api/class-consolemessage) event handler argument.
+ *
+ * **Usage**
+ *
+ * ```js
+ * electronApp.on('console', async msg => {
+ * const values = [];
+ * for (const arg of msg.args())
+ * values.push(await arg.jsonValue());
+ * console.log(...values);
+ * });
+ * await electronApp.evaluate(() => console.log('hello', 5, { foo: 'bar' }));
+ * ```
+ *
+ */
+ on(event: 'console', listener: (consoleMessage: ConsoleMessage) => any): this;
+
+ /**
+ * This event is issued for every window that is created **and loaded** in Electron. It contains a
+ * [Page](https://playwright.dev/docs/api/class-page) that can be used for Playwright automation.
+ */
+ on(event: 'window', listener: (page: Page) => any): this;
+
+ /**
+ * Adds an event listener that will be automatically removed after it is triggered once. See `addListener` for more information about this event.
+ */
+ once(event: 'close', listener: () => any): this;
+
+ /**
+ * Adds an event listener that will be automatically removed after it is triggered once. See `addListener` for more information about this event.
+ */
+ once(event: 'console', listener: (consoleMessage: ConsoleMessage) => any): this;
+
+ /**
+ * Adds an event listener that will be automatically removed after it is triggered once. See `addListener` for more information about this event.
+ */
+ once(event: 'window', listener: (page: Page) => any): this;
+
+ /**
+ * This event is issued when the application process has been terminated.
+ */
+ addListener(event: 'close', listener: () => any): this;
+
+ /**
+ * Emitted when JavaScript within the Electron main process calls one of console API methods, e.g. `console.log` or
+ * `console.dir`.
+ *
+ * The arguments passed into `console.log` are available on the
+ * [ConsoleMessage](https://playwright.dev/docs/api/class-consolemessage) event handler argument.
+ *
+ * **Usage**
+ *
+ * ```js
+ * electronApp.on('console', async msg => {
+ * const values = [];
+ * for (const arg of msg.args())
+ * values.push(await arg.jsonValue());
+ * console.log(...values);
+ * });
+ * await electronApp.evaluate(() => console.log('hello', 5, { foo: 'bar' }));
+ * ```
+ *
+ */
+ addListener(event: 'console', listener: (consoleMessage: ConsoleMessage) => any): this;
+
+ /**
+ * This event is issued for every window that is created **and loaded** in Electron. It contains a
+ * [Page](https://playwright.dev/docs/api/class-page) that can be used for Playwright automation.
+ */
+ addListener(event: 'window', listener: (page: Page) => any): this;
+
+ /**
+ * Removes an event listener added by `on` or `addListener`.
+ */
+ removeListener(event: 'close', listener: () => any): this;
+
+ /**
+ * Removes an event listener added by `on` or `addListener`.
+ */
+ removeListener(event: 'console', listener: (consoleMessage: ConsoleMessage) => any): this;
+
+ /**
+ * Removes an event listener added by `on` or `addListener`.
+ */
+ removeListener(event: 'window', listener: (page: Page) => any): this;
+
+ /**
+ * Removes an event listener added by `on` or `addListener`.
+ */
+ off(event: 'close', listener: () => any): this;
+
+ /**
+ * Removes an event listener added by `on` or `addListener`.
+ */
+ off(event: 'console', listener: (consoleMessage: ConsoleMessage) => any): this;
+
+ /**
+ * Removes an event listener added by `on` or `addListener`.
+ */
+ off(event: 'window', listener: (page: Page) => any): this;
+
+ /**
+ * This event is issued when the application process has been terminated.
+ */
+ prependListener(event: 'close', listener: () => any): this;
+
+ /**
+ * Emitted when JavaScript within the Electron main process calls one of console API methods, e.g. `console.log` or
+ * `console.dir`.
+ *
+ * The arguments passed into `console.log` are available on the
+ * [ConsoleMessage](https://playwright.dev/docs/api/class-consolemessage) event handler argument.
+ *
+ * **Usage**
+ *
+ * ```js
+ * electronApp.on('console', async msg => {
+ * const values = [];
+ * for (const arg of msg.args())
+ * values.push(await arg.jsonValue());
+ * console.log(...values);
+ * });
+ * await electronApp.evaluate(() => console.log('hello', 5, { foo: 'bar' }));
+ * ```
+ *
+ */
+ prependListener(event: 'console', listener: (consoleMessage: ConsoleMessage) => any): this;
+
+ /**
+ * This event is issued for every window that is created **and loaded** in Electron. It contains a
+ * [Page](https://playwright.dev/docs/api/class-page) that can be used for Playwright automation.
+ */
+ prependListener(event: 'window', listener: (page: Page) => any): this;
+
+ /**
+ * Returns the BrowserWindow object that corresponds to the given Playwright page.
+ * @param page Page to retrieve the window for.
+ */
+ browserWindow(page: Page): Promise<JSHandle>;
+
+ /**
+ * Closes Electron application.
+ */
+ close(): Promise<void>;
+
+ /**
+ * This method returns browser context that can be used for setting up context-wide routing, etc.
+ */
+ context(): BrowserContext;
+
+ /**
+ * Convenience method that waits for the first application window to be opened.
+ *
+ * **Usage**
+ *
+ * ```js
+ * const electronApp = await electron.launch({
+ * args: ['main.js']
+ * });
+ * const window = await electronApp.firstWindow();
+ * // ...
+ * ```
+ *
+ * @param options
+ */
+ firstWindow(options?: {
+ /**
+ * Maximum time to wait for in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The
+ * default value can be changed by using the
+ * [browserContext.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browser-context-set-default-timeout).
+ */
+ timeout?: number;
+ }): Promise<Page>;
+
+ /**
+ * Returns the main process for this Electron Application.
+ */
+ process(): ChildProcess;
+
+ /**
+ * This event is issued when the application process has been terminated.
+ */
+ waitForEvent(event: 'close', optionsOrPredicate?: { predicate?: () => boolean | Promise<boolean>, timeout?: number } | (() => boolean | Promise<boolean>)): Promise<void>;
+
+ /**
+ * Emitted when JavaScript within the Electron main process calls one of console API methods, e.g. `console.log` or
+ * `console.dir`.
+ *
+ * The arguments passed into `console.log` are available on the
+ * [ConsoleMessage](https://playwright.dev/docs/api/class-consolemessage) event handler argument.
+ *
+ * **Usage**
+ *
+ * ```js
+ * electronApp.on('console', async msg => {
+ * const values = [];
+ * for (const arg of msg.args())
+ * values.push(await arg.jsonValue());
+ * console.log(...values);
+ * });
+ * await electronApp.evaluate(() => console.log('hello', 5, { foo: 'bar' }));
+ * ```
+ *
+ */
+ waitForEvent(event: 'console', optionsOrPredicate?: { predicate?: (consoleMessage: ConsoleMessage) => boolean | Promise<boolean>, timeout?: number } | ((consoleMessage: ConsoleMessage) => boolean | Promise<boolean>)): Promise<ConsoleMessage>;
+
+ /**
+ * This event is issued for every window that is created **and loaded** in Electron. It contains a
+ * [Page](https://playwright.dev/docs/api/class-page) that can be used for Playwright automation.
+ */
+ waitForEvent(event: 'window', optionsOrPredicate?: { predicate?: (page: Page) => boolean | Promise<boolean>, timeout?: number } | ((page: Page) => boolean | Promise<boolean>)): Promise<Page>;
+
+
+ /**
+ * Convenience method that returns all the opened windows.
+ */
+ windows(): Array<Page>;
+
+ [Symbol.asyncDispose](): Promise<void>;
+}
+
+export const _electron: Electron;
+
// This is required to not export everything by default. See https://github.com/Microsoft/TypeScript/issues/19545#issuecomment-340490459
export {};
@@ -22255,6 +22572,64 @@ export interface WebSocket {
}
+/**
+ * Playwright supports Electron automation, shipped as a separate package.
+ *
+ * After installation, you can write a test or an automation script.
+ *
+ * **Supported Electron versions are:**
+ * - v12.2.0+
+ * - v13.4.0+
+ * - v14+
+ *
+ * **Known issues:**
+ *
+ * If you are not able to launch Electron and it will end up in timeouts during launch, try the following:
+ * - Ensure that `nodeCliInspect`
+ * ([FuseV1Options.EnableNodeCliInspectArguments](https://www.electronjs.org/docs/latest/tutorial/fuses#nodecliinspect))
+ * fuse is **not** set to `false`.
+ */
+export interface Electron {
+ /**
+ * Launches electron application specified with the
+ * [`executablePath`](https://playwright.dev/docs/api/class-electron#electron-launch-option-executable-path).
+ * @param options
+ */
+ launch(options?: {
+ /**
+ * Additional arguments to pass to the application when launching. You typically pass the main script name here.
+ */
+ args?: Array<string>;
+
+ /**
+ * Enable Chromium sandboxing. Defaults to `false`.
+ */
+ chromiumSandbox?: boolean;
+
+ /**
+ * Current working directory to launch application from.
+ */
+ cwd?: string;
+
+ /**
+ * Specifies environment variables that will be visible to Electron. Defaults to `process.env`.
+ */
+ env?: { [key: string]: string; };
+
+ /**
+ * Launches given Electron application. If not specified, launches the default Electron executable installed in this
+ * package, located at `node_modules/.bin/electron`.
+ */
+ executablePath?: string;
+
+ /**
+ * Maximum time in milliseconds to wait for the application to start. Defaults to `30000` (30 seconds). Pass `0` to
+ * disable timeout.
+ */
+ timeout?: number;
+ }): Promise<ElectronApplication>;
+}
+
export interface LaunchOptions {
/**
* **NOTE** Use custom browser args at your own risk, as some of them may break Playwright functionality.
diff --git a/packages/playwright-core/index.mjs b/packages/playwright-core/index.mjs
index 7df237cb64..0878c2161f 100644
--- a/packages/playwright-core/index.mjs
+++ b/packages/playwright-core/index.mjs
@@ -24,4 +24,5 @@ export const devices = playwright.devices;
export const errors = playwright.errors;
export const request = playwright.request;
export const _android = playwright._android;
+export const _electron = playwright._electron;
export default playwright;
diff --git a/packages/playwright-core/src/electron/DEPS.list b/packages/playwright-core/src/electron/DEPS.list
new file mode 100644
index 0000000000..33bd5201b0
--- /dev/null
+++ b/packages/playwright-core/src/electron/DEPS.list
@@ -0,0 +1,5 @@
+[*]
+../package.ts
+@isomorphic/**
+@utils/**
+node_modules/debug
diff --git a/packages/playwright-electron/src/electron.ts b/packages/playwright-core/src/electron/electron.ts
similarity index 95%
rename from packages/playwright-electron/src/electron.ts
rename to packages/playwright-core/src/electron/electron.ts
index c31c7aa873..94800edc61 100644
--- a/packages/playwright-electron/src/electron.ts
+++ b/packages/playwright-core/src/electron/electron.ts
@@ -17,7 +17,6 @@
import os from 'os';
import readline from 'readline';
import { EventEmitter } from 'events';
-import { chromium } from 'playwright/test';
import debug from 'debug';
import { launchProcess } from '@utils/processLauncher';
@@ -26,10 +25,13 @@ import { debugMode } from '@utils/debug';
import { ManualPromise } from '@isomorphic/manualPromise';
import { monotonicTime } from '@isomorphic/time';
+import { libPath } from '../package';
+
import type { BrowserWindow } from 'electron';
-import type { Browser, BrowserContext, JSHandle, Page, Worker } from 'playwright/test';
+import type { Browser, BrowserContext, JSHandle, Page, Worker } from '../../types/types';
+import type * as api from '../../types/types';
+import type { Playwright } from '../client/playwright';
import type childProcess from 'child_process';
-import type * as api from '../types';
const debugLogger = debug('pw:electron');
@@ -71,6 +73,12 @@ class Progress {
}
export class Electron implements api.Electron {
+ _playwright: Playwright;
+
+ constructor(playwright: Playwright) {
+ this._playwright = playwright;
+ }
+
async launch(options: ElectronLaunchOptions = {}): Promise<ElectronApplication> {
const timeout = options.timeout ?? (debugMode() === 'inspector' ? 0 : 3 * 60 * 1000);
const progress = new Progress(timeout, `electron.launch: Timeout ${timeout}ms exceeded`);
@@ -101,8 +109,9 @@ export class Electron implements api.Electron {
throw error;
}
// Only inject our loader for non-packaged apps; packaged apps may have
- // their own command-line handling.
- electronArguments.unshift('-r', require.resolve('./loader'));
+ // their own command-line handling. loader.js is emitted under
+ // lib/electron/ as a per-file build (see utils/build/build.js).
+ electronArguments.unshift('-r', libPath('electron', 'loader.js'));
}
let shell = false;
@@ -160,6 +169,7 @@ export class Electron implements api.Electron {
const debuggerDisconnectPromise = waitForLine(progress, launchedProcess, /Waiting for the debugger to disconnect\.\.\./);
try {
+ const chromium = this._playwright.chromium;
const nodeMatch = await nodeMatchPromise;
const worker = await chromium.connectToWorker(nodeMatch[1], { timeout: progress.timeUntilDeadline() });
@@ -345,5 +355,3 @@ async function waitForLine(progress: Progress, process: childProcess.ChildProces
process.removeListener('error', onFail);
}
}
-
-export const electron = new Electron();
diff --git a/packages/playwright-electron/src/loader.ts b/packages/playwright-core/src/electron/loader.ts
similarity index 100%
rename from packages/playwright-electron/src/loader.ts
rename to packages/playwright-core/src/electron/loader.ts
diff --git a/packages/playwright-core/src/inprocess.ts b/packages/playwright-core/src/inprocess.ts
index fba4fb5ad7..c65ae864f4 100644
--- a/packages/playwright-core/src/inprocess.ts
+++ b/packages/playwright-core/src/inprocess.ts
@@ -17,6 +17,7 @@
import { nodePlatform } from '@utils/nodePlatform';
import { AndroidServerLauncherImpl } from './androidServerImpl';
import { BrowserServerLauncherImpl } from './browserServerImpl';
+import { Electron } from './electron/electron';
import { DispatcherConnection, PlaywrightDispatcher, RootDispatcher, createPlaywright } from './server';
import { Connection } from './client/connection';
import { packageRoot } from './package';
@@ -43,6 +44,7 @@ export function createInProcessPlaywright(): PlaywrightAPI {
playwrightAPI.firefox._serverLauncher = new BrowserServerLauncherImpl('firefox');
playwrightAPI.webkit._serverLauncher = new BrowserServerLauncherImpl('webkit');
playwrightAPI._android._serverLauncher = new AndroidServerLauncherImpl();
+ (playwrightAPI as any)._electron = new Electron(playwrightAPI);
// Switch to async dispatch after we got Playwright object.
dispatcherConnection.onmessage = message => setImmediate(() => clientConnection.dispatch(message));
diff --git a/packages/playwright-core/types/types.d.ts b/packages/playwright-core/types/types.d.ts
index 05fb9e1ed8..d36153bd9f 100644
--- a/packages/playwright-core/types/types.d.ts
+++ b/packages/playwright-core/types/types.d.ts
@@ -16858,6 +16858,323 @@ export type AndroidKey =
export const _android: Android;
+//@ts-ignore this will be any if electron is not installed
+type ElectronType = typeof import('electron');
+
+/**
+ * Electron application representation. You can use
+ * [electron.launch([options])](https://playwright.dev/docs/api/class-electron#electron-launch) to obtain the
+ * application instance. This instance you can control main electron process as well as work with Electron windows:
+ *
+ * ```js
+ * const { _electron: electron } = require('playwright');
+ *
+ * (async () => {
+ * // Launch Electron app.
+ * const electronApp = await electron.launch({ args: ['main.js'] });
+ *
+ * // Evaluation expression in the Electron context.
+ * const appPath = await electronApp.evaluate(async ({ app }) => {
+ * // This runs in the main Electron process, parameter here is always
+ * // the result of the require('electron') in the main app script.
+ * return app.getAppPath();
+ * });
+ * console.log(appPath);
+ *
+ * // Get the first window that the app opens, wait if necessary.
+ * const window = await electronApp.firstWindow();
+ * // Print the title.
+ * console.log(await window.title());
+ * // Capture a screenshot.
+ * await window.screenshot({ path: 'intro.png' });
+ * // Direct Electron console to Node terminal.
+ * window.on('console', console.log);
+ * // Click button.
+ * await window.click('text=Click me');
+ * // Exit app.
+ * await electronApp.close();
+ * })();
+ * ```
+ *
+ */
+export interface ElectronApplication {
+ /**
+ * Returns the return value of
+ * [`pageFunction`](https://playwright.dev/docs/api/class-electronapplication#electron-application-evaluate-option-expression).
+ *
+ * If the function passed to the
+ * [electronApplication.evaluate(pageFunction[, arg])](https://playwright.dev/docs/api/class-electronapplication#electron-application-evaluate)
+ * returns a [Promise], then
+ * [electronApplication.evaluate(pageFunction[, arg])](https://playwright.dev/docs/api/class-electronapplication#electron-application-evaluate)
+ * would wait for the promise to resolve and return its value.
+ *
+ * If the function passed to the
+ * [electronApplication.evaluate(pageFunction[, arg])](https://playwright.dev/docs/api/class-electronapplication#electron-application-evaluate)
+ * returns a non-[Serializable] value, then
+ * [electronApplication.evaluate(pageFunction[, arg])](https://playwright.dev/docs/api/class-electronapplication#electron-application-evaluate)
+ * returns `undefined`. Playwright also supports transferring some additional values that are not serializable by
+ * `JSON`: `-0`, `NaN`, `Infinity`, `-Infinity`.
+ * @param pageFunction Function to be evaluated in the main Electron process.
+ * @param arg Optional argument to pass to
+ * [`pageFunction`](https://playwright.dev/docs/api/class-electronapplication#electron-application-evaluate-option-expression).
+ */
+ evaluate: JSHandle<ElectronType>['evaluate'];
+ /**
+ * Returns the return value of
+ * [`pageFunction`](https://playwright.dev/docs/api/class-electronapplication#electron-application-evaluate-handle-option-expression)
+ * as a [JSHandle](https://playwright.dev/docs/api/class-jshandle).
+ *
+ * The only difference between
+ * [electronApplication.evaluate(pageFunction[, arg])](https://playwright.dev/docs/api/class-electronapplication#electron-application-evaluate)
+ * and
+ * [electronApplication.evaluateHandle(pageFunction[, arg])](https://playwright.dev/docs/api/class-electronapplication#electron-application-evaluate-handle)
+ * is that
+ * [electronApplication.evaluateHandle(pageFunction[, arg])](https://playwright.dev/docs/api/class-electronapplication#electron-application-evaluate-handle)
+ * returns [JSHandle](https://playwright.dev/docs/api/class-jshandle).
+ *
+ * If the function passed to the
+ * [electronApplication.evaluateHandle(pageFunction[, arg])](https://playwright.dev/docs/api/class-electronapplication#electron-application-evaluate-handle)
+ * returns a [Promise], then
+ * [electronApplication.evaluateHandle(pageFunction[, arg])](https://playwright.dev/docs/api/class-electronapplication#electron-application-evaluate-handle)
+ * would wait for the promise to resolve and return its value.
+ * @param pageFunction Function to be evaluated in the main Electron process.
+ * @param arg Optional argument to pass to
+ * [`pageFunction`](https://playwright.dev/docs/api/class-electronapplication#electron-application-evaluate-handle-option-expression).
+ */
+ evaluateHandle: JSHandle<ElectronType>['evaluateHandle'];
+ /**
+ * This event is issued when the application process has been terminated.
+ */
+ on(event: 'close', listener: () => any): this;
+
+ /**
+ * Emitted when JavaScript within the Electron main process calls one of console API methods, e.g. `console.log` or
+ * `console.dir`.
+ *
+ * The arguments passed into `console.log` are available on the
+ * [ConsoleMessage](https://playwright.dev/docs/api/class-consolemessage) event handler argument.
+ *
+ * **Usage**
+ *
+ * ```js
+ * electronApp.on('console', async msg => {
+ * const values = [];
+ * for (const arg of msg.args())
+ * values.push(await arg.jsonValue());
+ * console.log(...values);
+ * });
+ * await electronApp.evaluate(() => console.log('hello', 5, { foo: 'bar' }));
+ * ```
+ *
+ */
+ on(event: 'console', listener: (consoleMessage: ConsoleMessage) => any): this;
+
+ /**
+ * This event is issued for every window that is created **and loaded** in Electron. It contains a
+ * [Page](https://playwright.dev/docs/api/class-page) that can be used for Playwright automation.
+ */
+ on(event: 'window', listener: (page: Page) => any): this;
+
+ /**
+ * Adds an event listener that will be automatically removed after it is triggered once. See `addListener` for more information about this event.
+ */
+ once(event: 'close', listener: () => any): this;
+
+ /**
+ * Adds an event listener that will be automatically removed after it is triggered once. See `addListener` for more information about this event.
+ */
+ once(event: 'console', listener: (consoleMessage: ConsoleMessage) => any): this;
+
+ /**
+ * Adds an event listener that will be automatically removed after it is triggered once. See `addListener` for more information about this event.
+ */
+ once(event: 'window', listener: (page: Page) => any): this;
+
+ /**
+ * This event is issued when the application process has been terminated.
+ */
+ addListener(event: 'close', listener: () => any): this;
+
+ /**
+ * Emitted when JavaScript within the Electron main process calls one of console API methods, e.g. `console.log` or
+ * `console.dir`.
+ *
+ * The arguments passed into `console.log` are available on the
+ * [ConsoleMessage](https://playwright.dev/docs/api/class-consolemessage) event handler argument.
+ *
+ * **Usage**
+ *
+ * ```js
+ * electronApp.on('console', async msg => {
+ * const values = [];
+ * for (const arg of msg.args())
+ * values.push(await arg.jsonValue());
+ * console.log(...values);
+ * });
+ * await electronApp.evaluate(() => console.log('hello', 5, { foo: 'bar' }));
+ * ```
+ *
+ */
+ addListener(event: 'console', listener: (consoleMessage: ConsoleMessage) => any): this;
+
+ /**
+ * This event is issued for every window that is created **and loaded** in Electron. It contains a
+ * [Page](https://playwright.dev/docs/api/class-page) that can be used for Playwright automation.
+ */
+ addListener(event: 'window', listener: (page: Page) => any): this;
+
+ /**
+ * Removes an event listener added by `on` or `addListener`.
+ */
+ removeListener(event: 'close', listener: () => any): this;
+
+ /**
+ * Removes an event listener added by `on` or `addListener`.
+ */
+ removeListener(event: 'console', listener: (consoleMessage: ConsoleMessage) => any): this;
+
+ /**
+ * Removes an event listener added by `on` or `addListener`.
+ */
+ removeListener(event: 'window', listener: (page: Page) => any): this;
+
+ /**
+ * Removes an event listener added by `on` or `addListener`.
+ */
+ off(event: 'close', listener: () => any): this;
+
+ /**
+ * Removes an event listener added by `on` or `addListener`.
+ */
+ off(event: 'console', listener: (consoleMessage: ConsoleMessage) => any): this;
+
+ /**
+ * Removes an event listener added by `on` or `addListener`.
+ */
+ off(event: 'window', listener: (page: Page) => any): this;
+
+ /**
+ * This event is issued when the application process has been terminated.
+ */
+ prependListener(event: 'close', listener: () => any): this;
+
+ /**
+ * Emitted when JavaScript within the Electron main process calls one of console API methods, e.g. `console.log` or
+ * `console.dir`.
+ *
+ * The arguments passed into `console.log` are available on the
+ * [ConsoleMessage](https://playwright.dev/docs/api/class-consolemessage) event handler argument.
+ *
+ * **Usage**
+ *
+ * ```js
+ * electronApp.on('console', async msg => {
+ * const values = [];
+ * for (const arg of msg.args())
+ * values.push(await arg.jsonValue());
+ * console.log(...values);
+ * });
+ * await electronApp.evaluate(() => console.log('hello', 5, { foo: 'bar' }));
+ * ```
+ *
+ */
+ prependListener(event: 'console', listener: (consoleMessage: ConsoleMessage) => any): this;
+
+ /**
+ * This event is issued for every window that is created **and loaded** in Electron. It contains a
+ * [Page](https://playwright.dev/docs/api/class-page) that can be used for Playwright automation.
+ */
+ prependListener(event: 'window', listener: (page: Page) => any): this;
+
+ /**
+ * Returns the BrowserWindow object that corresponds to the given Playwright page.
+ * @param page Page to retrieve the window for.
+ */
+ browserWindow(page: Page): Promise<JSHandle>;
+
+ /**
+ * Closes Electron application.
+ */
+ close(): Promise<void>;
+
+ /**
+ * This method returns browser context that can be used for setting up context-wide routing, etc.
+ */
+ context(): BrowserContext;
+
+ /**
+ * Convenience method that waits for the first application window to be opened.
+ *
+ * **Usage**
+ *
+ * ```js
+ * const electronApp = await electron.launch({
+ * args: ['main.js']
+ * });
+ * const window = await electronApp.firstWindow();
+ * // ...
+ * ```
+ *
+ * @param options
+ */
+ firstWindow(options?: {
+ /**
+ * Maximum time to wait for in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The
+ * default value can be changed by using the
+ * [browserContext.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browser-context-set-default-timeout).
+ */
+ timeout?: number;
+ }): Promise<Page>;
+
+ /**
+ * Returns the main process for this Electron Application.
+ */
+ process(): ChildProcess;
+
+ /**
+ * This event is issued when the application process has been terminated.
+ */
+ waitForEvent(event: 'close', optionsOrPredicate?: { predicate?: () => boolean | Promise<boolean>, timeout?: number } | (() => boolean | Promise<boolean>)): Promise<void>;
+
+ /**
+ * Emitted when JavaScript within the Electron main process calls one of console API methods, e.g. `console.log` or
+ * `console.dir`.
+ *
+ * The arguments passed into `console.log` are available on the
+ * [ConsoleMessage](https://playwright.dev/docs/api/class-consolemessage) event handler argument.
+ *
+ * **Usage**
+ *
+ * ```js
+ * electronApp.on('console', async msg => {
+ * const values = [];
+ * for (const arg of msg.args())
+ * values.push(await arg.jsonValue());
+ * console.log(...values);
+ * });
+ * await electronApp.evaluate(() => console.log('hello', 5, { foo: 'bar' }));
+ * ```
+ *
+ */
+ waitForEvent(event: 'console', optionsOrPredicate?: { predicate?: (consoleMessage: ConsoleMessage) => boolean | Promise<boolean>, timeout?: number } | ((consoleMessage: ConsoleMessage) => boolean | Promise<boolean>)): Promise<ConsoleMessage>;
+
+ /**
+ * This event is issued for every window that is created **and loaded** in Electron. It contains a
+ * [Page](https://playwright.dev/docs/api/class-page) that can be used for Playwright automation.
+ */
+ waitForEvent(event: 'window', optionsOrPredicate?: { predicate?: (page: Page) => boolean | Promise<boolean>, timeout?: number } | ((page: Page) => boolean | Promise<boolean>)): Promise<Page>;
+
+
+ /**
+ * Convenience method that returns all the opened windows.
+ */
+ windows(): Array<Page>;
+
+ [Symbol.asyncDispose](): Promise<void>;
+}
+
+export const _electron: Electron;
+
// This is required to not export everything by default. See https://github.com/Microsoft/TypeScript/issues/19545#issuecomment-340490459
export {};
@@ -22255,6 +22572,64 @@ export interface WebSocket {
}
+/**
+ * Playwright supports Electron automation, shipped as a separate package.
+ *
+ * After installation, you can write a test or an automation script.
+ *
+ * **Supported Electron versions are:**
+ * - v12.2.0+
+ * - v13.4.0+
+ * - v14+
+ *
+ * **Known issues:**
+ *
+ * If you are not able to launch Electron and it will end up in timeouts during launch, try the following:
+ * - Ensure that `nodeCliInspect`
+ * ([FuseV1Options.EnableNodeCliInspectArguments](https://www.electronjs.org/docs/latest/tutorial/fuses#nodecliinspect))
+ * fuse is **not** set to `false`.
+ */
+export interface Electron {
+ /**
+ * Launches electron application specified with the
+ * [`executablePath`](https://playwright.dev/docs/api/class-electron#electron-launch-option-executable-path).
+ * @param options
+ */
+ launch(options?: {
+ /**
+ * Additional arguments to pass to the application when launching. You typically pass the main script name here.
+ */
+ args?: Array<string>;
+
+ /**
+ * Enable Chromium sandboxing. Defaults to `false`.
+ */
+ chromiumSandbox?: boolean;
+
+ /**
+ * Current working directory to launch application from.
+ */
+ cwd?: string;
+
+ /**
+ * Specifies environment variables that will be visible to Electron. Defaults to `process.env`.
+ */
+ env?: { [key: string]: string; };
+
+ /**
+ * Launches given Electron application. If not specified, launches the default Electron executable installed in this
+ * package, located at `node_modules/.bin/electron`.
+ */
+ executablePath?: string;
+
+ /**
+ * Maximum time in milliseconds to wait for the application to start. Defaults to `30000` (30 seconds). Pass `0` to
+ * disable timeout.
+ */
+ timeout?: number;
+ }): Promise<ElectronApplication>;
+}
+
export interface LaunchOptions {
/**
* **NOTE** Use custom browser args at your own risk, as some of them may break Playwright functionality.
diff --git a/docs/src/electron-api/class-electronfixtures.md b/packages/playwright-electron/class-electronfixtures.md
similarity index 100%
rename from docs/src/electron-api/class-electronfixtures.md
rename to packages/playwright-electron/class-electronfixtures.md
diff --git a/packages/playwright-electron/index.d.ts b/packages/playwright-electron/index.d.ts
index 71d3a172bd..d2b7923866 100644
--- a/packages/playwright-electron/index.d.ts
+++ b/packages/playwright-electron/index.d.ts
@@ -30,6 +30,7 @@ import type { Electron, ElectronApplication } from './types';
export * from './types';
export { expect, devices, mergeExpects, mergeTests } from 'playwright/test';
+export { _electron as electron } from 'playwright-core';
export type ElectronAppOptions = Parameters<Electron['launch']>[0];
export type PlaywrightTestOptions = Pick<BasePlaywrightTestOptions, 'testIdAttribute'> & {
diff --git a/packages/playwright-electron/package.json b/packages/playwright-electron/package.json
index c746d6eca3..676105e4a1 100644
--- a/packages/playwright-electron/package.json
+++ b/packages/playwright-electron/package.json
@@ -1,6 +1,7 @@
{
"name": "@playwright/electron",
- "version": "1.60.0-next",
+ "version": "0.0.0",
+ "private": true,
"description": "Playwright for Electron",
"repository": {
"type": "git",
@@ -21,6 +22,6 @@
}
},
"dependencies": {
- "playwright": "1.60.0-next"
+ "playwright": "*"
}
}
diff --git a/packages/playwright-electron/src/DEPS.list b/packages/playwright-electron/src/DEPS.list
index 2eff62db60..e5344b5cbb 100644
--- a/packages/playwright-electron/src/DEPS.list
+++ b/packages/playwright-electron/src/DEPS.list
@@ -1,5 +1,2 @@
[*]
-@isomorphic/**
-@utils/**
node_modules/playwright
-node_modules/debug
diff --git a/packages/playwright-electron/src/index.ts b/packages/playwright-electron/src/index.ts
index a25c567dc4..5a2446a093 100644
--- a/packages/playwright-electron/src/index.ts
+++ b/packages/playwright-electron/src/index.ts
@@ -15,10 +15,9 @@
*/
// @ts-expect-error
-import { _utilityTest } from 'playwright/test';
+import { _utilityTest, _electron as electron } from 'playwright/test';
import { selectors } from 'playwright/test';
-import { electron } from './electron';
export { expect, devices, defineConfig, mergeExpects, mergeTests } from 'playwright/test';
export { electron, selectors };
diff --git a/packages/playwright-electron/types.d.ts b/packages/playwright-electron/types.d.ts
index 99608c6bf9..e2add353db 100644
--- a/packages/playwright-electron/types.d.ts
+++ b/packages/playwright-electron/types.d.ts
@@ -1,4 +1,3 @@
-// This file is generated by /utils/generate_types/index.js
/**
* Copyright (c) Microsoft Corporation.
*
@@ -15,388 +14,4 @@
* limitations under the License.
*/
-import type { BrowserContext, ConsoleMessage, JSHandle, Page } from 'playwright-core';
-import type { ChildProcess } from 'child_process';
-
export * from 'playwright-core';
-
-//@ts-ignore this will be any if electron is not installed
-type ElectronType = typeof import('electron');
-
-/**
- * Electron application representation. You can use
- * [electron.launch([options])](https://playwright.dev/docs/api/class-electron#electron-launch) to obtain the
- * application instance. This instance you can control main electron process as well as work with Electron windows:
- *
- * ```js
- * const { _electron: electron } = require('playwright');
- *
- * (async () => {
- * // Launch Electron app.
- * const electronApp = await electron.launch({ args: ['main.js'] });
- *
- * // Evaluation expression in the Electron context.
- * const appPath = await electronApp.evaluate(async ({ app }) => {
- * // This runs in the main Electron process, parameter here is always
- * // the result of the require('electron') in the main app script.
- * return app.getAppPath();
- * });
- * console.log(appPath);
- *
- * // Get the first window that the app opens, wait if necessary.
- * const window = await electronApp.firstWindow();
- * // Print the title.
- * console.log(await window.title());
- * // Capture a screenshot.
- * await window.screenshot({ path: 'intro.png' });
- * // Direct Electron console to Node terminal.
- * window.on('console', console.log);
- * // Click button.
- * await window.click('text=Click me');
- * // Exit app.
- * await electronApp.close();
- * })();
- * ```
- *
- */
-export interface ElectronApplication {
- /**
- * Returns the return value of
- * [`pageFunction`](https://playwright.dev/docs/api/class-electronapplication#electron-application-evaluate-option-expression).
- *
- * If the function passed to the
- * [electronApplication.evaluate(pageFunction[, arg])](https://playwright.dev/docs/api/class-electronapplication#electron-application-evaluate)
- * returns a [Promise], then
- * [electronApplication.evaluate(pageFunction[, arg])](https://playwright.dev/docs/api/class-electronapplication#electron-application-evaluate)
- * would wait for the promise to resolve and return its value.
- *
- * If the function passed to the
- * [electronApplication.evaluate(pageFunction[, arg])](https://playwright.dev/docs/api/class-electronapplication#electron-application-evaluate)
- * returns a non-[Serializable] value, then
- * [electronApplication.evaluate(pageFunction[, arg])](https://playwright.dev/docs/api/class-electronapplication#electron-application-evaluate)
- * returns `undefined`. Playwright also supports transferring some additional values that are not serializable by
- * `JSON`: `-0`, `NaN`, `Infinity`, `-Infinity`.
- * @param pageFunction Function to be evaluated in the main Electron process.
- * @param arg Optional argument to pass to
- * [`pageFunction`](https://playwright.dev/docs/api/class-electronapplication#electron-application-evaluate-option-expression).
- */
- evaluate: JSHandle<ElectronType>['evaluate'];
- /**
- * Returns the return value of
- * [`pageFunction`](https://playwright.dev/docs/api/class-electronapplication#electron-application-evaluate-handle-option-expression)
- * as a [JSHandle](https://playwright.dev/docs/api/class-jshandle).
- *
- * The only difference between
- * [electronApplication.evaluate(pageFunction[, arg])](https://playwright.dev/docs/api/class-electronapplication#electron-application-evaluate)
- * and
- * [electronApplication.evaluateHandle(pageFunction[, arg])](https://playwright.dev/docs/api/class-electronapplication#electron-application-evaluate-handle)
- * is that
- * [electronApplication.evaluateHandle(pageFunction[, arg])](https://playwright.dev/docs/api/class-electronapplication#electron-application-evaluate-handle)
- * returns [JSHandle](https://playwright.dev/docs/api/class-jshandle).
- *
- * If the function passed to the
- * [electronApplication.evaluateHandle(pageFunction[, arg])](https://playwright.dev/docs/api/class-electronapplication#electron-application-evaluate-handle)
- * returns a [Promise], then
- * [electronApplication.evaluateHandle(pageFunction[, arg])](https://playwright.dev/docs/api/class-electronapplication#electron-application-evaluate-handle)
- * would wait for the promise to resolve and return its value.
- * @param pageFunction Function to be evaluated in the main Electron process.
- * @param arg Optional argument to pass to
- * [`pageFunction`](https://playwright.dev/docs/api/class-electronapplication#electron-application-evaluate-handle-option-expression).
- */
- evaluateHandle: JSHandle<ElectronType>['evaluateHandle'];
- /**
- * This event is issued when the application process has been terminated.
- */
- on(event: 'close', listener: () => any): this;
-
- /**
- * Emitted when JavaScript within the Electron main process calls one of console API methods, e.g. `console.log` or
- * `console.dir`.
- *
- * The arguments passed into `console.log` are available on the
- * [ConsoleMessage](https://playwright.dev/docs/api/class-consolemessage) event handler argument.
- *
- * **Usage**
- *
- * ```js
- * electronApp.on('console', async msg => {
- * const values = [];
- * for (const arg of msg.args())
- * values.push(await arg.jsonValue());
- * console.log(...values);
- * });
- * await electronApp.evaluate(() => console.log('hello', 5, { foo: 'bar' }));
- * ```
- *
- */
- on(event: 'console', listener: (consoleMessage: ConsoleMessage) => any): this;
-
- /**
- * This event is issued for every window that is created **and loaded** in Electron. It contains a
- * [Page](https://playwright.dev/docs/api/class-page) that can be used for Playwright automation.
- */
- on(event: 'window', listener: (page: Page) => any): this;
-
- /**
- * Adds an event listener that will be automatically removed after it is triggered once. See `addListener` for more information about this event.
- */
- once(event: 'close', listener: () => any): this;
-
- /**
- * Adds an event listener that will be automatically removed after it is triggered once. See `addListener` for more information about this event.
- */
- once(event: 'console', listener: (consoleMessage: ConsoleMessage) => any): this;
-
- /**
- * Adds an event listener that will be automatically removed after it is triggered once. See `addListener` for more information about this event.
- */
- once(event: 'window', listener: (page: Page) => any): this;
-
- /**
- * This event is issued when the application process has been terminated.
- */
- addListener(event: 'close', listener: () => any): this;
-
- /**
- * Emitted when JavaScript within the Electron main process calls one of console API methods, e.g. `console.log` or
- * `console.dir`.
- *
- * The arguments passed into `console.log` are available on the
- * [ConsoleMessage](https://playwright.dev/docs/api/class-consolemessage) event handler argument.
- *
- * **Usage**
- *
- * ```js
- * electronApp.on('console', async msg => {
- * const values = [];
- * for (const arg of msg.args())
- * values.push(await arg.jsonValue());
- * console.log(...values);
- * });
- * await electronApp.evaluate(() => console.log('hello', 5, { foo: 'bar' }));
- * ```
- *
- */
- addListener(event: 'console', listener: (consoleMessage: ConsoleMessage) => any): this;
-
- /**
- * This event is issued for every window that is created **and loaded** in Electron. It contains a
- * [Page](https://playwright.dev/docs/api/class-page) that can be used for Playwright automation.
- */
- addListener(event: 'window', listener: (page: Page) => any): this;
-
- /**
- * Removes an event listener added by `on` or `addListener`.
- */
- removeListener(event: 'close', listener: () => any): this;
-
- /**
- * Removes an event listener added by `on` or `addListener`.
- */
- removeListener(event: 'console', listener: (consoleMessage: ConsoleMessage) => any): this;
-
- /**
- * Removes an event listener added by `on` or `addListener`.
- */
- removeListener(event: 'window', listener: (page: Page) => any): this;
-
- /**
- * Removes an event listener added by `on` or `addListener`.
- */
- off(event: 'close', listener: () => any): this;
-
- /**
- * Removes an event listener added by `on` or `addListener`.
- */
- off(event: 'console', listener: (consoleMessage: ConsoleMessage) => any): this;
-
- /**
- * Removes an event listener added by `on` or `addListener`.
- */
- off(event: 'window', listener: (page: Page) => any): this;
-
- /**
- * This event is issued when the application process has been terminated.
- */
- prependListener(event: 'close', listener: () => any): this;
-
- /**
- * Emitted when JavaScript within the Electron main process calls one of console API methods, e.g. `console.log` or
- * `console.dir`.
- *
- * The arguments passed into `console.log` are available on the
- * [ConsoleMessage](https://playwright.dev/docs/api/class-consolemessage) event handler argument.
- *
- * **Usage**
- *
- * ```js
- * electronApp.on('console', async msg => {
- * const values = [];
- * for (const arg of msg.args())
- * values.push(await arg.jsonValue());
- * console.log(...values);
- * });
- * await electronApp.evaluate(() => console.log('hello', 5, { foo: 'bar' }));
- * ```
- *
- */
- prependListener(event: 'console', listener: (consoleMessage: ConsoleMessage) => any): this;
-
- /**
- * This event is issued for every window that is created **and loaded** in Electron. It contains a
- * [Page](https://playwright.dev/docs/api/class-page) that can be used for Playwright automation.
- */
- prependListener(event: 'window', listener: (page: Page) => any): this;
-
- /**
- * Returns the BrowserWindow object that corresponds to the given Playwright page.
- * @param page Page to retrieve the window for.
- */
- browserWindow(page: Page): Promise<JSHandle>;
-
- /**
- * Closes Electron application.
- */
- close(): Promise<void>;
-
- /**
- * This method returns browser context that can be used for setting up context-wide routing, etc.
- */
- context(): BrowserContext;
-
- /**
- * Convenience method that waits for the first application window to be opened.
- *
- * **Usage**
- *
- * ```js
- * const electronApp = await electron.launch({
- * args: ['main.js']
- * });
- * const window = await electronApp.firstWindow();
- * // ...
- * ```
- *
- * @param options
- */
- firstWindow(options?: {
- /**
- * Maximum time to wait for in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The
- * default value can be changed by using the
- * [browserContext.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browser-context-set-default-timeout).
- */
- timeout?: number;
- }): Promise<Page>;
-
- /**
- * Returns the main process for this Electron Application.
- */
- process(): ChildProcess;
-
- /**
- * This event is issued when the application process has been terminated.
- */
- waitForEvent(event: 'close', optionsOrPredicate?: { predicate?: () => boolean | Promise<boolean>, timeout?: number } | (() => boolean | Promise<boolean>)): Promise<void>;
-
- /**
- * Emitted when JavaScript within the Electron main process calls one of console API methods, e.g. `console.log` or
- * `console.dir`.
- *
- * The arguments passed into `console.log` are available on the
- * [ConsoleMessage](https://playwright.dev/docs/api/class-consolemessage) event handler argument.
- *
- * **Usage**
- *
- * ```js
- * electronApp.on('console', async msg => {
- * const values = [];
- * for (const arg of msg.args())
- * values.push(await arg.jsonValue());
- * console.log(...values);
- * });
- * await electronApp.evaluate(() => console.log('hello', 5, { foo: 'bar' }));
- * ```
- *
- */
- waitForEvent(event: 'console', optionsOrPredicate?: { predicate?: (consoleMessage: ConsoleMessage) => boolean | Promise<boolean>, timeout?: number } | ((consoleMessage: ConsoleMessage) => boolean | Promise<boolean>)): Promise<ConsoleMessage>;
-
- /**
- * This event is issued for every window that is created **and loaded** in Electron. It contains a
- * [Page](https://playwright.dev/docs/api/class-page) that can be used for Playwright automation.
- */
- waitForEvent(event: 'window', optionsOrPredicate?: { predicate?: (page: Page) => boolean | Promise<boolean>, timeout?: number } | ((page: Page) => boolean | Promise<boolean>)): Promise<Page>;
-
-
- /**
- * Convenience method that returns all the opened windows.
- */
- windows(): Array<Page>;
-
- [Symbol.asyncDispose](): Promise<void>;
-}
-
-export const electron: Electron;
-
-// This is required to not export everything by default. See https://github.com/Microsoft/TypeScript/issues/19545#issuecomment-340490459
-export {};
-
-
-/**
- * Playwright supports Electron automation, shipped as a separate package.
- *
- * After installation, you can write a test or an automation script.
- *
- * **Supported Electron versions are:**
- * - v12.2.0+
- * - v13.4.0+
- * - v14+
- *
- * **Known issues:**
- *
- * If you are not able to launch Electron and it will end up in timeouts during launch, try the following:
- * - Ensure that `nodeCliInspect`
- * ([FuseV1Options.EnableNodeCliInspectArguments](https://www.electronjs.org/docs/latest/tutorial/fuses#nodecliinspect))
- * fuse is **not** set to `false`.
- */
-export interface Electron {
- /**
- * Launches electron application specified with the
- * [`executablePath`](https://playwright.dev/docs/api/class-electron#electron-launch-option-executable-path).
- * @param options
- */
- launch(options?: {
- /**
- * Additional arguments to pass to the application when launching. You typically pass the main script name here.
- */
- args?: Array<string>;
-
- /**
- * Enable Chromium sandboxing. Defaults to `false`.
- */
- chromiumSandbox?: boolean;
-
- /**
- * Current working directory to launch application from.
- */
- cwd?: string;
-
- /**
- * Specifies environment variables that will be visible to Electron. Defaults to `process.env`.
- */
- env?: { [key: string]: string; };
-
- /**
- * Launches given Electron application. If not specified, launches the default Electron executable installed in this
- * package, located at `node_modules/.bin/electron`.
- */
- executablePath?: string;
-
- /**
- * Maximum time in milliseconds to wait for the application to start. Defaults to `30000` (30 seconds). Pass `0` to
- * disable timeout.
- */
- timeout?: number;
- }): Promise<ElectronApplication>;
-}
-
-
diff --git a/tests/installation/fixture-scripts/sanity-electron.js b/tests/installation/fixture-scripts/sanity-electron.js
index 27436733dd..bd507c7f6b 100644
--- a/tests/installation/fixture-scripts/sanity-electron.js
+++ b/tests/installation/fixture-scripts/sanity-electron.js
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-const { electron } = require('@playwright/electron');
+const { _electron: electron } = require('@playwright/test');
const path = require('path');
(async () => {
@@ -25,7 +25,7 @@ const path = require('path');
await application.close();
if (appPath !== __dirname)
throw new Error(`Malformed app path: got "${appPath}", expected "${__dirname}"`);
- console.log(`@playwright/electron SUCCESS`);
+ console.log(`@playwright/test electron SUCCESS`);
})().catch(err => {
console.error(err);
process.exit(1);
diff --git a/tests/installation/playwright-electron-should-work.spec.ts b/tests/installation/playwright-electron-should-work.spec.ts
index 3def51a4d7..88d83ceb17 100755
--- a/tests/installation/playwright-electron-should-work.spec.ts
+++ b/tests/installation/playwright-electron-should-work.spec.ts
@@ -19,11 +19,11 @@ import { expect } from '../../packages/playwright-test';
import path from 'path';
test('electron should work', async ({ exec, tsc, writeFiles }) => {
- await exec('npm i @playwright/electron [email protected]');
+ await exec('npm i @playwright/test [email protected]');
await exec('node sanity-electron.js');
await writeFiles({
'test.ts':
- `import { electron, ElectronApplication, Electron } from '@playwright/electron';`
+ `import { _electron as electron, ElectronApplication, Electron } from '@playwright/test';`
});
await tsc('test.ts');
});
@@ -32,7 +32,7 @@ test('electron should work with special characters in path', async ({ exec, tmpW
test.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/30755' });
const folderName = path.join(tmpWorkspace, '!@#$% тест with spaces and 😊');
- await exec('npm i @playwright/electron [email protected]');
+ await exec('npm i @playwright/test [email protected]');
await fs.promises.mkdir(folderName);
for (const file of ['electron-app.js', 'sanity-electron.js'])
await fs.promises.copyFile(path.join(tmpWorkspace, file), path.join(folderName, file));
@@ -42,11 +42,10 @@ test('electron should work with special characters in path', async ({ exec, tmpW
});
test('should work when wrapped inside @playwright/test and trace is enabled', async ({ exec, tmpWorkspace, writeFiles }) => {
- await exec('npm i -D @playwright/test @playwright/electron [email protected]');
+ await exec('npm i -D @playwright/test [email protected]');
await writeFiles({
'electron-with-tracing.spec.ts': `
- import { test, expect } from '@playwright/test';
- import { electron } from '@playwright/electron';
+ import { test, expect, _electron as electron } from '@playwright/test';
test('should work', async ({}) => {
const electronApp = await electron.launch({ args: [${JSON.stringify(path.join(__dirname, '../electron/electron-window-app.js'))}] });
diff --git a/utils/build/build.js b/utils/build/build.js
index de16c98250..7551e5061e 100644
--- a/utils/build/build.js
+++ b/utils/build/build.js
@@ -549,10 +549,9 @@ for (const pkg of workspace.packages()) {
}));
}
-// playwright-electron/lib/index.js — self-contained bundle that inlines
-// @utils/* and @isomorphic/* sources (via tsconfig paths) plus the `node_modules`
-// deps. playwright, electron, and the sibling loader.js are resolved at
-// runtime.
+// playwright-electron/lib/index.js — thin test-runner integration shim that
+// re-exports `playwright._electron`. Resolved at runtime against the parent
+// `playwright` install.
{
const electronPkg = filePath('packages/playwright-electron');
steps.push(new EsbuildStep({
@@ -562,18 +561,7 @@ for (const pkg of workspace.packages()) {
external: [
'playwright',
'playwright/*',
- 'electron',
- 'electron/*',
- './loader',
],
- }, [filePath('packages/utils'), filePath('packages/isomorphic')]));
-
- // loader.ts is preloaded inside the Electron main process via `-r` and is
- // already self-contained (no @utils/@isomorphic imports). Compile it
- // per-file so the output stays a thin shim.
- steps.push(new EsbuildStep({
- entryPoints: [path.join(electronPkg, 'src/loader.ts')],
- outdir: path.join(electronPkg, 'lib'),
}));
}
@@ -589,6 +577,10 @@ steps.push(new EsbuildStep({
filePath('packages/playwright-core/src/entry/mcp.ts'),
filePath('packages/playwright-core/src/entry/oopBrowserDownload.ts'),
+ // Electron loader — preloaded inside the Electron main process via `-r`.
+ // Self-contained (no @utils/@isomorphic imports) — emitted as a thin shim.
+ filePath('packages/playwright-core/src/electron/loader.ts'),
+
// CLI client tools, should be a separate bundle.
filePath('packages/playwright-core/src/tools/cli-client/*.ts'),
filePath('packages/playwright-core/src/package.ts'),
@@ -956,7 +948,6 @@ onChanges.push({
'utils/generate_types/overrides.d.ts',
'utils/generate_types/overrides-test.d.ts',
'utils/generate_types/overrides-testReporter.d.ts',
- 'utils/generate_types/overrides-electron.d.ts',
'utils/generate_types/exported.json',
'packages/playwright-core/src/server/chromium/protocol.d.ts',
],
diff --git a/utils/generate_types/index.js b/utils/generate_types/index.js
index 2778848fa4..b5e5128fc0 100644
--- a/utils/generate_types/index.js
+++ b/utils/generate_types/index.js
@@ -497,10 +497,10 @@ class TypesGenerator {
}
(async function () {
- const coreDocumentation = parseApi(path.join(PROJECT_DIR, 'docs', 'src', 'api'));
+ const coreDocumentation = parseApi(path.join(PROJECT_DIR, 'docs', 'src', 'api'))
+ .mergeWith(parseApi(path.join(PROJECT_DIR, 'docs', 'src', 'electron-api'), path.join(PROJECT_DIR, 'docs', 'src', 'api', 'params.md')));
const testDocumentation = parseApi(path.join(PROJECT_DIR, 'docs', 'src', 'test-api'), path.join(PROJECT_DIR, 'docs', 'src', 'api', 'params.md'));
const reporterDocumentation = parseApi(path.join(PROJECT_DIR, 'docs', 'src', 'test-reporter-api'));
- const electronDocumentation = parseApi(path.join(PROJECT_DIR, 'docs', 'src', 'electron-api'), path.join(PROJECT_DIR, 'docs', 'src', 'api', 'params.md'));
const assertionClasses = new Set([
'APIResponseAssertions',
'GenericAssertions',
@@ -519,7 +519,6 @@ class TypesGenerator {
documentation,
doNotGenerate: new Set([
...assertionClasses,
- ...electronDocumentation.classesArray.map(cls => cls.name),
]),
});
let types = await generator.generateTypes(path.join(__dirname, 'overrides.d.ts'));
@@ -610,21 +609,6 @@ class TypesGenerator {
return await generator.generateTypes(path.join(__dirname, 'overrides-testReporter.d.ts'));
}
- /**
- * @returns {Promise<string>}
- */
- async function generateElectronTypes() {
- const documentation = coreDocumentation.mergeWith(electronDocumentation);
- const generator = new TypesGenerator({
- documentation,
- doNotGenerate: new Set([
- ...coreDocumentation.classesArray.map(cls => cls.name),
- 'ElectronFixtures',
- ]),
- });
- return await generator.generateTypes(path.join(__dirname, 'overrides-electron.d.ts'));
- }
-
/**
* @param {string} filePath
* @param {string} content
@@ -654,8 +638,6 @@ class TypesGenerator {
writeFile(path.join(clientTypesDir, 'types.d.ts'), coreTypes, true);
writeFile(path.join(playwrightTypesDir, 'test.d.ts'), await generateTestTypes(), true);
writeFile(path.join(playwrightTypesDir, 'testReporter.d.ts'), await generateReporterTypes(), true);
- const electronTypesDir = path.join(PROJECT_DIR, 'packages', 'playwright-electron');
- writeFile(path.join(electronTypesDir, 'types.d.ts'), await generateElectronTypes(), true);
process.exit(0);
})().catch(e => {
console.error(e);
diff --git a/utils/generate_types/overrides-electron.d.ts b/utils/generate_types/overrides-electron.d.ts
deleted file mode 100644
index bd01b7ae03..0000000000
--- a/utils/generate_types/overrides-electron.d.ts
+++ /dev/null
@@ -1,33 +0,0 @@
-/**
- * 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 type { BrowserContext, ConsoleMessage, JSHandle, Page } from 'playwright-core';
-import type { ChildProcess } from 'child_process';
-
-export * from 'playwright-core';
-
-//@ts-ignore this will be any if electron is not installed
-type ElectronType = typeof import('electron');
-
-export interface ElectronApplication {
- evaluate: JSHandle<ElectronType>['evaluate'];
- evaluateHandle: JSHandle<ElectronType>['evaluateHandle'];
-}
-
-export const electron: Electron;
-
-// This is required to not export everything by default. See https://github.com/Microsoft/TypeScript/issues/19545#issuecomment-340490459
-export {};
diff --git a/utils/generate_types/overrides.d.ts b/utils/generate_types/overrides.d.ts
index bc0b2eba4a..dba016b023 100644
--- a/utils/generate_types/overrides.d.ts
+++ b/utils/generate_types/overrides.d.ts
@@ -384,5 +384,15 @@ export type AndroidKey =
export const _android: Android;
+//@ts-ignore this will be any if electron is not installed
+type ElectronType = typeof import('electron');
+
+export interface ElectronApplication {
+ evaluate: JSHandle<ElectronType>['evaluate'];
+ evaluateHandle: JSHandle<ElectronType>['evaluateHandle'];
+}
+
+export const _electron: Electron;
+
// This is required to not export everything by default. See https://github.com/Microsoft/TypeScript/issues/19545#issuecomment-340490459
export {};
diff --git a/utils/workspace.js b/utils/workspace.js
index 2845171293..2f98fc2f3e 100755
--- a/utils/workspace.js
+++ b/utils/workspace.js
@@ -214,11 +214,6 @@ const workspace = new Workspace(ROOT_PATH, [
path: path.join(ROOT_PATH, 'packages', 'playwright-ct-vue'),
files: ['LICENSE'],
}),
- new PWPackage({
- name: '@playwright/electron',
- path: path.join(ROOT_PATH, 'packages', 'playwright-electron'),
- files: ['LICENSE'],
- }),
]);
if (require.main === module) {