Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/electron-service/docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ Other 2.x and 7.x versions generally work because the layout of `dist-electron/`

### 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:
If you are not specifying a Chromedriver binary then the service will download and use the appropriate version for your app's Electron version. With WebdriverIO v10 this is the Chromedriver bundled with that Electron release, which the service passes on as the `wdio:electronVersion` capability. 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:

This is **required**, not merely an override, when the project running the tests has no `electron` dependency of its own — otherwise the run fails with *"Could not determine the Electron version under test"*. Setting `appBinaryPath` alone is not enough. If the version is a fork or nightly that the service cannot map to a Chromium version, use [User Managed](#user-managed) instead. See [Common Issues](./common-issues.md#could-not-determine-the-electron-version-under-test).

Expand Down
12 changes: 10 additions & 2 deletions packages/electron-service/src/launcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,18 @@ export default class ElectronLaunchService implements Services.ServiceInstance {

await Promise.all(
caps.map(async (cap) => {
const electronVersion = cap.browserVersion || localElectronVersion || '';
const electronVersion =
((cap as Record<string, unknown>)['wdio:electronVersion'] as string | undefined) ||
cap.browserVersion ||
localElectronVersion ||
'';
let chromiumVersion: string | undefined = await getChromiumVersion(electronVersion);

(cap as ElectronServiceCapabilities & Record<string, unknown>)['wdio:electronVersion'] = electronVersion;
// WebdriverIO downloads Chromedriver from the Electron release named here, so it only gets a release the map
// knows, never a Chromium browserVersion or a fork build
if (chromiumVersion) {
(cap as ElectronServiceCapabilities & Record<string, unknown>)['wdio:electronVersion'] = electronVersion;
}

if (Number.parseInt(electronVersion.split('.')[0], 10) < 26 && !cap['wdio:chromedriverOptions']?.binary) {
const invalidElectronVersionError = new SevereServiceError(
Expand Down
20 changes: 18 additions & 2 deletions packages/electron-service/test/launcher.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,6 @@ describe('Electron Launch Service', () => {
},
'wdio:electronServiceOptions': {},
'wdio:chromiumVersion': undefined,
'wdio:electronVersion': 'some-version',
'wdio:enforceWebDriverClassic': true,
});
});
Expand All @@ -609,7 +608,6 @@ describe('Electron Launch Service', () => {
'wdio:chromedriverOptions': {},
'wdio:electronServiceOptions': {},
'wdio:chromiumVersion': '150.0.7871.129',
'wdio:electronVersion': 'some-version',
'wdio:enforceWebDriverClassic': true,
});
});
Expand All @@ -622,6 +620,24 @@ describe('Electron Launch Service', () => {
expect(probeChromiumVersion).not.toHaveBeenCalled();
});

it('should not pass a Chromium browserVersion on as wdio:electronVersion', async () => {
const capabilities: WebdriverIO.Capabilities[] = [
{ browserName: 'electron', browserVersion: '116.0.5845.190' },
];
await instance?.onPrepare({} as never, capabilities);
expect(capabilities[0].browserVersion).toBe('116.0.5845.190');
expect((capabilities[0] as Record<string, unknown>)['wdio:electronVersion']).toBeUndefined();
});

it('should take the Electron version from an existing wdio:electronVersion', async () => {
const capabilities = [
{ browserName: 'electron', browserVersion: '116.0.5845.190', 'wdio:electronVersion': '26.2.2' },
] as WebdriverIO.Capabilities[];
await instance?.onPrepare({} as never, capabilities);
expect(capabilities[0].browserVersion).toBe('116.0.5845.190');
expect((capabilities[0] as Record<string, unknown>)['wdio:electronVersion']).toBe('26.2.2');
});

it('should use the Electron version from the local package dependencies when browserVersion is not provided', async () => {
// Mock electron version that matches the expected chrome version
(getElectronVersion as Mock).mockResolvedValueOnce('26.0.0');
Expand Down
Loading