From e547801d1436dafff9584959e66647b79980a2df Mon Sep 17 00:00:00 2001 From: Sam Maister Date: Thu, 1 Oct 2026 00:56:34 +0100 Subject: [PATCH] fix(electron): only pass known Electron releases on as wdio:electronVersion WebdriverIO v10 downloads Chromedriver from the Electron release named in wdio:electronVersion. The launcher copied browserVersion into it, so a Chromium version (as the "Could not determine the Chromium version" error advises) or a fork build reached it too, and WebdriverIO would fetch a release that doesn't exist. - Set wdio:electronVersion only when the Electron -> Chromium map knows the version. Everything else keeps to the browserVersion path, which WebdriverIO v9 uses anyway. - Read an existing wdio:electronVersion first, so a set value wins and a second conversion doesn't read the Chromium browserVersion as the Electron version. Co-Authored-By: Claude Opus 5.5 --- .../electron-service/docs/configuration.md | 2 +- packages/electron-service/src/launcher.ts | 12 +++++++++-- .../electron-service/test/launcher.spec.ts | 20 +++++++++++++++++-- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/packages/electron-service/docs/configuration.md b/packages/electron-service/docs/configuration.md index b6c48b846..59573654d 100644 --- a/packages/electron-service/docs/configuration.md +++ b/packages/electron-service/docs/configuration.md @@ -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). diff --git a/packages/electron-service/src/launcher.ts b/packages/electron-service/src/launcher.ts index 5f357a047..7ae61bb46 100644 --- a/packages/electron-service/src/launcher.ts +++ b/packages/electron-service/src/launcher.ts @@ -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)['wdio:electronVersion'] as string | undefined) || + cap.browserVersion || + localElectronVersion || + ''; let chromiumVersion: string | undefined = await getChromiumVersion(electronVersion); - (cap as ElectronServiceCapabilities & Record)['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)['wdio:electronVersion'] = electronVersion; + } if (Number.parseInt(electronVersion.split('.')[0], 10) < 26 && !cap['wdio:chromedriverOptions']?.binary) { const invalidElectronVersionError = new SevereServiceError( diff --git a/packages/electron-service/test/launcher.spec.ts b/packages/electron-service/test/launcher.spec.ts index 03d75f35e..25a8529f5 100644 --- a/packages/electron-service/test/launcher.spec.ts +++ b/packages/electron-service/test/launcher.spec.ts @@ -582,7 +582,6 @@ describe('Electron Launch Service', () => { }, 'wdio:electronServiceOptions': {}, 'wdio:chromiumVersion': undefined, - 'wdio:electronVersion': 'some-version', 'wdio:enforceWebDriverClassic': true, }); }); @@ -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, }); }); @@ -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)['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)['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');