WebdriverIO desktop testing configuration
WebdriverIO can be configured for Electron testing by setting services to ['electron'] and capabilities with browserName 'electron'. The 'wdio:electronServiceOptions' object can include appBinaryPath (path to bundled application executable) and appArgs (array of command-line arguments to pass to the app).
WebdriverIO test example accessing Electron APIs
WebdriverIO allows tests to execute arbitrary Electron main process code using browser.electron.execute(). The callback receives the electron module as its first parameter, followed by any additional parameters passed from the test. This example shows creating a message dialog: await browser.electron.execute((electron, param1, param2, param3) => { const appWindow = electron.BrowserWindow.getFocusedWindow(); electron.dialog.showMessageBox(appWindow, { message: 'Hello World!', detail: `${param1} + ${param2} + ${param3} = ${param1 + param2 + param3}` }) }, 1, 2, 3)
WebdriverIO keyboard input test example
WebdriverIO provides browser.keys() to simulate keyboard input and custom matchers for assertions. This example verifies keyboard input: await browser.keys(['y', 'o']); await expect($('keypress-count')).toHaveText('YO')
Installing WebdriverIO with Electron support
Run 'npm init wdio@latest ./' in the project root to start WebdriverIO's configuration wizard. Select 'Desktop Testing - of Electron Applications' when asked 'What type of testing would you like to do?'. This installs necessary packages and generates a wdio.conf.js configuration file.
Running WebdriverIO tests
Execute tests with 'npx wdio run wdio.conf.js'. WebdriverIO automatically launches and shuts down the Electron application during test runs.
Selenium with Electron using electron-chromedriver
To use Selenium with Electron, install electron-chromedriver via npm, then run './node_modules/.bin/chromedriver' to start the ChromeDriver server (listens on port 9515 by default). This standalone server implements WebDriver's wire protocol for Chromium.
Selenium WebDriver connection to Electron app
When connecting Selenium to Electron, manually specify the ChromeDriver server URL (e.g., http://localhost:9515) and the Electron binary path. Example: const driver = new webdriver.Builder().usingServer('http://localhost:9515').withCapabilities({'goog:chromeOptions': {binary: '/Path-to-Your-App.app/Contents/MacOS/Electron'}}).forBrowser('chrome').build(). For selenium-webdriver <= 3.6.0, use .forBrowser('electron').
Playwright Electron support and installation
Playwright has experimental Electron support using Electron's Chrome DevTools Protocol (CDP) support. Install with 'npm install --save-dev @playwright/test'. Tutorial references @playwright/test@1.52.0; check Playwright's releases page for compatibility with your version.
Playwright launch and evaluate Electron main process
Launch an Electron app in development mode using electron.launch({ args: ['.'] }), passing the path to the main process entry point in args. Use electronApp.evaluate() to run code in the main process and access main process modules. Example: const isPackaged = await electronApp.evaluate(async ({ app }) => { return app.isPackaged })
Playwright capture screenshots from Electron windows
Access individual BrowserWindow instances as Page objects using electronApp.firstWindow(). Call window.screenshot({ path: 'intro.png' }) to save screenshots from Electron windows.
Playwright test file patterns and configuration
Playwright Test automatically runs any files matching the regex pattern `.*(test|spec)\.(js|ts|mjs)`. This can be customized in Playwright Test configuration options. TypeScript is supported out of the box.
Custom Electron test driver using child_process and IPC
A custom test driver can be created using Node.js' child_process.spawn() API to launch the Electron process with stdio configured as ['inherit', 'inherit', 'inherit', 'ipc']. The test suite and Electron app communicate via process.send() and process.on('message') events.
Custom TestDriver class implementation pattern
A TestDriver class manages spawning the Electron process with stdio: ['inherit', 'inherit', 'inherit', 'ipc'] and env variable APP_TEST_DRIVER=1. It implements an RPC pattern: the rpc(cmd, ...args) method sends messages with msgId, cmd, and args; the process listens for responses with matching msgId to resolve/reject promises. The Electron app's main.js checks process.env.APP_TEST_DRIVER and registers a message handler that executes methods from a METHODS object and sends back { msgId, resolve } or { msgId, reject }.
WebDriver definition and ChromeDriver purpose
WebDriver is an open source tool for automated testing of web apps across many browsers. It provides capabilities for navigating web pages, user input, and JavaScript execution. ChromeDriver is a standalone server that implements WebDriver's wire protocol for Chromium and is developed by members of the Chromium and WebDriver teams.
Electron example guides available topics
Electron provides example guides for common features including: Message ports for communicating between different processes, Device access for hardware like Bluetooth/USB/Serial, Keyboard shortcuts for local and global shortcuts, Multithreading using Web Workers for OS-level JavaScript threads, Offscreen rendering to obtain BrowserWindow content as a bitmap, Spellchecker for built-in spell checking, and Web embeds for embedding third-party web content.
Electron Fiddle tool for running examples
Electron Fiddle is the easiest way to run the provided example guides. Code samples include an 'Open in Fiddle' button that allows opening examples directly in the Fiddle tool.
xvfb-maybe usage example
xvfb-maybe electron-mocha ./test/*.js
Electron requires display driver for tests
Electron is based on Chromium and requires a display driver to function. If Chromium cannot find a display driver, Electron will fail to launch and tests will not execute, regardless of how they are run.
Virtual display driver needed for headless CI systems
Testing Electron apps on headless CI systems like Travis CI, CircleCI, Jenkins, or similar requires configuration with a virtual display driver.
Xvfb provides virtual framebuffer for testing
Xvfb is a virtual framebuffer that implements the X11 display server protocol. It performs all graphical operations in memory without showing any screen output, making it suitable for headless testing environments.
DISPLAY environment variable configuration for Electron
Create a virtual Xvfb screen and export an environment variable called DISPLAY that points to it. Chromium in Electron will automatically look for the $DISPLAY environment variable, so no further configuration of the app is required.
xvfb-maybe tool automates virtual display setup
The xvfb-maybe tool automatically configures Xvfb when required by the system. Prepend test commands with xvfb-maybe; on Windows or macOS it does nothing, and on Linux in a headless environment it sets up Xvfb automatically.
CircleCI has Xvfb pre-configured
CircleCI has Xvfb and the $DISPLAY environment variable already set up, so no further configuration is required for testing Electron apps.
AppVeyor supports Electron out of the box
AppVeyor runs on Windows and supports Selenium, Chromium, Electron and similar tools out of the box with no configuration required.