API Reference
This document provides a complete reference for all browser.electron.* methods and exported utility functions provided by the service.
Table of Contents
- Utility Functions
- Execution Methods
- Mocking Methods
- Mock Object Methods
- Mock Object Properties
- Electron Class Mock
Utility Functions
These functions are exported directly from the package and can be used independently of the WDIO test runner.
createElectronCapabilities()
Creates an Electron capabilities object for use with startWdioSession() or in WDIO configuration. Builds the correct capability structure including goog:chromeOptions and wdio:electronServiceOptions.
Signature:
import { createElectronCapabilities } from '@wdio/electron-service';
createElectronCapabilities(options: ElectronServiceOptions): ElectronStandaloneCapability
Parameters:
| Parameter | Type | Description |
|---|---|---|
options | ElectronServiceOptions | Service options. Must include at least appBinaryPath or appEntryPoint. |
Common fields:
| Field | Type | Description |
|---|---|---|
appBinaryPath | string | Path to the compiled Electron app binary |
appEntryPoint | string | Path to the unpackaged app entry point (e.g., main.js) |
appArgs | string[] | Command-line arguments passed to the app |
captureMainProcessLogs | boolean | Enable main process log capture |
captureRendererLogs | boolean | Enable renderer process log capture |
logDir | string | Directory for standalone mode logs |
See Configuration for the full list of ElectronServiceOptions fields.
Returns:
ElectronStandaloneCapability - A single capabilities object
Throws:
| Error | Condition |
|---|---|
Error | If neither appBinaryPath nor appEntryPoint is provided |
Example:
import { startWdioSession, createElectronCapabilities } from '@wdio/electron-service';
const caps = createElectronCapabilities({
appBinaryPath: './dist/mac/MyApp.app/Contents/MacOS/MyApp',
appArgs: ['--disable-gpu', '--headless'],
captureMainProcessLogs: true,
logDir: './test-logs',
});
const browser = await startWdioSession([caps]);
See Also:
getElectronBinaryPath()
Resolves the path to the Electron binary for a given app directory. Uses the same detection logic as the service (reading package.json, checking Electron Forge/Builder configs) without starting a session.
Signature:
import { getElectronBinaryPath } from '@wdio/electron-service';
getElectronBinaryPath(appDir: string): Promise<string>
Parameters:
| Parameter | Type | Description |
|---|---|---|
appDir | string | Path to the Electron app directory (must contain a package.json) |
Returns:
Promise<string> - The resolved path to the Electron binary
Throws:
| Error | Condition |
|---|---|
Error | If no package.json is found in appDir |
Error | If the binary path cannot be resolved |
Example:
import { getElectronBinaryPath } from '@wdio/electron-service';
const binaryPath = await getElectronBinaryPath('/path/to/my-electron-app');
console.log(binaryPath);
// e.g. '/path/to/my-electron-app/dist/mac-arm64/MyApp.app/Contents/MacOS/MyApp'
See Also: