முக்கிய உள்ளடக்கத்திற்கு செல்க

Configuration

The service can be configured by setting wdio:electronServiceOptions either on the service level or capability level, in which capability level configurations take precedence, e.g. the following WebdriverIO configuration:

wdio.conf.ts

export const config = {
// ...
services: [
[
'electron',
{
appBinaryPath: '/foo/bar/myApp'
},
],
],
capabilities: [
{
'browserName': 'electron',
'wdio:electronServiceOptions': {
appBinaryPath: '/foo/bar/myOtherApp'
appArgs: ['foo', 'bar'],
},
},
],
// ...
};

...would result in the following configuration object:

{
"appBinaryPath": "/foo/bar/myOtherApp",
"appArgs": ["foo", "bar"]
}

Service Options

The service supports the following configuration options:

appBinaryPath:

The path to the Electron binary of the app for testing. In most cases the service will determine the path to your app automatically, but if this fails for some reason, e.g. your app is in a different repository from your tests, then it is recommended to set this value manually.

Type: string

appArgs:

An array of string arguments to be passed through to the app on execution of the test run. Electron command line switches and some Chromium switches can be used here.

Type: string[]

clearMocks:

Calls .mockClear() on all mocked APIs before each test. This will clear mock history, but not reset its implementation.

Type: boolean

resetMocks:

Calls .mockReset() on all mocked APIs before each test. This will clear mock history and reset its implementation to an empty function (will return undefined).

Type: boolean

restoreMocks:

Calls .mockRestore() on all mocked APIs before each test. This will restore the original API function, the mock will be removed.

Type: boolean

Chromedriver Configuration

wdio-electron-service needs Chromedriver to work. The Chromedriver version needs to be appropriate for the version of Electron that your app was built with, you can either let the service handle this (default) or manage it yourself.

Service Managed

If you are not specifying a Chromedriver binary then the service will download and use the appropriate version for your app's Electron version. The Electron version of your app is determined by the version of electron or electron-nightly in your package.json, however you may want to override this behaviour - for instance, if the app you are testing is in a different repo from the tests. You can specify the Electron version manually by setting the browserVersion capability, as shown in the example configuration below:

wdio.conf.ts

export const config = {
// ...
services: ['electron'],
capabilities: [
{
browserName: 'electron',
browserVersion: '28.0.0',
},
],
// ...
};

User Managed

If your app uses a version of Electron which is lower than v26 then you will need to manually configure Chromedriver.

This is because WDIO uses Chrome for Testing to download Chromedriver, which only provides Chromedriver versions of v115 or newer.

In order to manage Chromedriver yourself you can install it directly or via some other means like electron-chromedriver, in this case you will need to tell WebdriverIO where your Chromedriver binary is through its custom wdio:chromedriverOptions capability.

For example, in order to use WDIO with an Electron v19 app, you will have to download Chromedriver 102.0.5005.61 from https://chromedriver.chromium.org/downloads. You should then specify the binary path in the WDIO config as follows:

wdio.conf.ts

export const config = {
// ...
services: ['electron'],
capabilities: [
{
'browserName': 'electron',
'wdio:chromedriverOptions': {
binary: '/Users/wdio/Downloads/chromedriver', // path to Chromedriver you just downloaded
},
},
],
// ...
};

Welcome! How can I help?

WebdriverIO AI Copilot