new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Playwright · all subjects

electron

50 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

Electron automation experimental support and namespace access

Playwright has experimental support for Electron automation. Access the electron namespace via: const { _electron } = require('playwright');

Supported Electron versions for Playwright automation

Supported Electron versions are: v12.2.0+, v13.4.0+, and v14+.

Electron launch timeout troubleshooting with nodeCliInspect fuse

If Electron fails to launch and times out, ensure that the nodeCliInspect fuse (FuseV1Options.EnableNodeCliInspectArguments) is not set to false.

Mocking native Electron dialogs in tests

Playwright does not intercept native Electron dialog API calls (dialog.showOpenDialog, dialog.showSaveDialog, dialog.showMessageBox, etc.) because they happen in the Electron main process and go directly to OS APIs. Use ElectronApplication.evaluate to replace these methods in the main process for deterministic testing without OS-level UI.

Example: stubbing Electron dialog.showSaveDialog

await electronApp.evaluate(({ dialog }, filePath) => { dialog.showSaveDialog = () => Promise.resolve({ canceled: false, filePath }); }, '/path/to/saved.txt');

Example: stubbing Electron dialog.showMessageBox

await electronApp.evaluate(({ dialog }) => { dialog.showMessageBox = () => Promise.resolve({ response: 0, checkboxChecked: false }); });

Stubbing synchronous Electron dialog methods

Synchronous variants of Electron dialogs (showOpenDialogSync, showSaveDialogSync, showMessageBoxSync) can be stubbed the same way as async variants — return the value directly instead of a Promise.

Stubbed dialog replacement persists until app closes

When stubbing Electron dialog methods via ElectronApplication.evaluate, the replacement persists until the application is closed.

Electron.launch method signature and return

Electron.launch launches an electron application specified with the executablePath option and returns an ElectronApplication instance.

Electron.launch executablePath option

executablePath (string): Launches the given Electron application. If not specified, launches the default Electron executable installed in this package, located at node_modules/.bin/electron.

Electron.launch args option

args (Array<string>): Additional arguments to pass to the application when launching. Typically used to pass the main script name.

Electron.launch cwd option

cwd (string): Current working directory to launch application from.

Electron.launch env option

env (Object<string, string>): Specifies environment variables that will be visible to Electron. Defaults to process.env.

Electron.launch timeout option

timeout (float): Maximum time in milliseconds to wait for the application to start. Defaults to 30000 (30 seconds). Pass 0 to disable timeout.

Example: launching and interacting with Electron app

const { _electron: electron } = require('playwright'); (async () => { const electronApp = await electron.launch({ args: ['main.js'] }); const appPath = await electronApp.evaluate(async ({ app }) => { return app.getAppPath(); }); console.log(appPath); const window = await electronApp.firstWindow(); console.log(await window.title()); await window.screenshot({ path: 'intro.png' }); window.on('console', console.log); await window.click('text=Click me'); await electronApp.close(); })();

AndroidDevice represents a connected Android device

AndroidDevice represents a connected device, either real hardware or emulated. Devices can be obtained using the Android.devices method.

AndroidDevice.close event emitted on disconnection

The close event is emitted when the device connection gets closed. The event passes the AndroidDevice as an argument.

AndroidDevice.webView event for new WebView detection

The webView event is emitted when a new WebView instance is detected. The event passes an AndroidWebView as an argument.

AndroidDevice.close method disconnects from device

The async close method disconnects from the device.

AndroidDevice.drag method drags widgets to a destination

The async drag method drags the widget defined by a selector towards a destination point. It accepts a selector parameter of type AndroidSelector, a dest parameter containing x and y float coordinates, an optional speed parameter in pixels per second, and an optional timeout parameter.

AndroidDevice.fill method fills input boxes

The async fill method fills a specific selector input box with text. It accepts a selector parameter of type AndroidSelector, a text parameter as a string, and an optional timeout parameter.

AndroidDevice.fling method flings widgets in direction

The async fling method flings the widget defined by a selector in a specified direction. It accepts a selector parameter of type AndroidSelector, a direction parameter accepting 'down', 'up', 'left', or 'right', an optional speed parameter in pixels per second, and an optional timeout parameter.

AndroidDevice.info method returns widget information

The async info method returns information about a widget defined by a selector parameter of type AndroidSelector. It returns an AndroidElementInfo object.

AndroidDevice.input property provides input control

The input property is of type AndroidInput and provides access to input control methods.

AndroidDevice.installApk method installs APK files

The async installApk method installs an APK on the device. It accepts a file parameter which is either a string path to the APK file or a Buffer containing APK content. It accepts an optional args parameter as an array of strings to pass to the shell:cmd package install call, defaulting to '-r -t -S'.

AndroidDevice.launchBrowser launches Chrome on device

The async launchBrowser method launches Chrome browser on the device and returns its persistent BrowserContext. It accepts an optional pkg parameter to launch a different package instead of default Chrome for Android. It also accepts shared context parameters, proxy configuration, and browser arguments options.

AndroidDevice.longTap performs long tap gesture

The async longTap method performs a long tap on the widget defined by a selector parameter of type AndroidSelector. It accepts an optional timeout parameter.

AndroidDevice.model returns device model string

The model method returns a string containing the device model.

AndroidDevice.open launches shell process and returns socket

The async open method launches a process in the shell on the device and returns an AndroidSocket to communicate with the launched process. It accepts a command parameter containing the shell command to execute.

AndroidDevice.pinchClose closes pinch gesture

The async pinchClose method pinches the widget defined by a selector in the closing direction. It accepts a selector parameter of type AndroidSelector, a percent parameter as a float representing the size of the pinch as a percentage of the widget's size, an optional speed parameter in pixels per second, and an optional timeout parameter.

AndroidDevice.pinchOpen opens pinch gesture

The async pinchOpen method pinches the widget defined by a selector in the open direction. It accepts a selector parameter of type AndroidSelector, a percent parameter as a float representing the size of the pinch as a percentage of the widget's size, an optional speed parameter in pixels per second, and an optional timeout parameter.

AndroidDevice.press presses key in widget

The async press method presses a specific key in the widget defined by a selector. It accepts a selector parameter of type AndroidSelector, a key parameter of type AndroidKey, and an optional timeout parameter.

AndroidDevice.push copies file to device

The async push method copies a file to the device. It accepts a file parameter which is either a string path to the file or a Buffer containing file content, a path parameter as a string for the path to the file on the device, and an optional mode parameter as an int defaulting to 644 (rw-r--r--).

AndroidDevice.screenshot captures device screenshot

The async screenshot method returns a Buffer with the captured screenshot of the device. It accepts an optional path parameter to save the image to disk. If the path is relative, it is resolved relative to the current working directory.

AndroidDevice.scroll scrolls widget in direction

The async scroll method scrolls the widget defined by a selector in a specified direction. It accepts a selector parameter of type AndroidSelector, a direction parameter accepting 'down', 'up', 'left', or 'right', a percent parameter as a float for distance to scroll as a percentage of the widget's size, an optional speed parameter in pixels per second, and an optional timeout parameter.

AndroidDevice.serial returns device serial number

The serial method returns a string containing the device serial number.

AndroidDevice.setDefaultTimeout sets timeout for all methods

The setDefaultTimeout method changes the default maximum time for all methods accepting a timeout option. It accepts a timeout parameter in milliseconds as a float.

AndroidDevice.shell executes shell command on device

The async shell method executes a shell command on the device and returns a Buffer containing its output. It accepts a command parameter as a string containing the shell command to execute.

AndroidDevice.swipe swipes widget in direction

The async swipe method swipes the widget defined by a selector in a specified direction. It accepts a selector parameter of type AndroidSelector, a direction parameter accepting 'down', 'up', 'left', or 'right', a percent parameter as a float for distance to swipe as a percentage of the widget's size, an optional speed parameter in pixels per second, and an optional timeout parameter.

AndroidDevice.tap taps on widget

The async tap method taps on the widget defined by a selector parameter of type AndroidSelector. It accepts an optional duration parameter in milliseconds and an optional timeout parameter.

AndroidDevice.wait waits for widget state change

The async wait method waits for a specific selector to either appear or disappear, depending on the state option. It accepts a selector parameter of type AndroidSelector, an optional state parameter which can be 'gone' to wait for element to not be present or default to wait for element to be present, and an optional timeout parameter.

AndroidDevice.waitForEvent waits for events with predicate

The async waitForEvent method waits for an event to fire and passes its value into a predicate function. It returns when the predicate returns a truthy value. It accepts an event parameter, and an optionsOrPredicate parameter which can be a function receiving event data or an object with a predicate function and optional timeout in milliseconds (defaulting to 30000/30 seconds, or 0 to disable). The default timeout can be changed using setDefaultTimeout.

AndroidDevice.webView waits for and returns WebView

The async webView method waits until an AndroidWebView matching a selector is opened and returns it. If an AndroidWebView matching the selector is already open, it returns immediately. It accepts a selector parameter as an object with optional pkg (package identifier) and socketName (webview socket name) properties, and an optional timeout parameter.

AndroidDevice.webViews returns currently open WebViews

The webViews method returns an array of AndroidWebView objects representing all currently open WebViews.

AndroidSocket class purpose and creation

AndroidSocket is a way to communicate with a process launched on an AndroidDevice. Use AndroidDevice.open to open a socket.

AndroidSocket.close event

The close event is emitted when the socket is closed.

AndroidSocket.data event

The data event is emitted when data is available to read from the socket. The event argument is a Buffer containing the data.

AndroidSocket.close method

The close method is an async function that closes the socket.

AndroidSocket.write method

The write method is an async function that writes data to the socket. It accepts a data parameter of type Buffer containing the data to write.

ElectronApplication.console event

The ElectronApplication.console event is emitted when the Electron main process calls console API methods, allowing monitoring of console output from the main process.

Give your agent this brain