diff --git a/fixtures/electron-in-dependencies/package.json b/fixtures/electron-in-dependencies/package.json index 6226e85b..89a7edf1 100644 --- a/fixtures/electron-in-dependencies/package.json +++ b/fixtures/electron-in-dependencies/package.json @@ -4,7 +4,7 @@ "description": "Electron found in dependencies", "scripts": {}, "dependencies": { - "electron": "^25.0.0" + "electron": "^26.0.0" }, "devDependencies": {} } diff --git a/fixtures/electron-in-dev-dependencies/package.json b/fixtures/electron-in-dev-dependencies/package.json index 39585a9d..de9ff121 100644 --- a/fixtures/electron-in-dev-dependencies/package.json +++ b/fixtures/electron-in-dev-dependencies/package.json @@ -5,6 +5,6 @@ "scripts": {}, "dependencies": {}, "devDependencies": { - "electron": "^25.0.0" + "electron": "^26.0.0" } } diff --git a/fixtures/old-electron/package.json b/fixtures/old-electron/package.json new file mode 100644 index 00000000..7aec5fa8 --- /dev/null +++ b/fixtures/old-electron/package.json @@ -0,0 +1,10 @@ +{ + "name": "fixture-old-electron", + "version": "1.0.0", + "description": "Old Electron found in devDependencies", + "scripts": {}, + "dependencies": {}, + "devDependencies": { + "electron": "^25.0.0" + } +} diff --git a/packages/wdio-electron-service/src/launcher.ts b/packages/wdio-electron-service/src/launcher.ts index ca77f33f..a66ec74a 100644 --- a/packages/wdio-electron-service/src/launcher.ts +++ b/packages/wdio-electron-service/src/launcher.ts @@ -47,10 +47,18 @@ export default class ElectronLaunchService implements Services.ServiceInstance { await Promise.all( caps.map(async (cap) => { - const electronVersion = cap.browserVersion || localElectronVersion; + const electronVersion = cap.browserVersion || localElectronVersion || ''; const chromiumVersion = await getChromiumVersion(electronVersion); log.info(`Found Electron v${electronVersion} with Chromedriver v${chromiumVersion}`); + if (Number.parseInt(electronVersion.split('.')[0]) < 26 && !cap['wdio:chromedriverOptions']?.binary) { + const invalidElectronVersionError = new SevereServiceError( + 'Electron version must be 26 or higher for auto-configuration of Chromedriver. If you want to use an older version of Electron, you must configure Chromedriver manually using the wdio:chromedriverOptions capability', + ); + log.error(invalidElectronVersionError.message); + throw invalidElectronVersionError; + } + let { appBinaryPath, appEntryPoint, diff --git a/packages/wdio-electron-service/test/launcher.spec.ts b/packages/wdio-electron-service/test/launcher.spec.ts index dd80435b..18d334b5 100644 --- a/packages/wdio-electron-service/test/launcher.spec.ts +++ b/packages/wdio-electron-service/test/launcher.spec.ts @@ -57,6 +57,10 @@ beforeEach(async () => { version: '26.2.2', chrome: '116.0.5845.190', }, + { + version: '32.0.1', + chrome: '128.0.6613.36', + }, ]); }); @@ -88,6 +92,59 @@ describe('onPrepare', () => { ); }); + it('should throw an error when the local Electron version is older than v26 and Chromedriver is not configured manually', async () => { + instance = new LaunchService( + options, + [] as never, + { + services: [['electron', options]], + rootDir: getFixtureDir('old-electron'), + } as Options.Testrunner, + ); + const capabilities: WebdriverIO.Capabilities[] = [ + { + browserName: 'electron', + }, + ]; + await expect(() => instance?.onPrepare({} as never, capabilities)).rejects.toThrow( + 'Electron version must be 26 or higher for auto-configuration of Chromedriver. If you want to use an older version of Electron, you must configure Chromedriver manually using the wdio:chromedriverOptions capability', + ); + }); + + it('should not throw an error when the local Electron version is older than v26 and Chromedriver is configured manually', async () => { + instance = new LaunchService( + options, + [] as never, + { + services: [['electron', options]], + rootDir: getFixtureDir('old-electron'), + } as Options.Testrunner, + ); + const capabilities: WebdriverIO.Capabilities[] = [ + { + 'browserName': 'electron', + 'wdio:chromedriverOptions': { + binary: '/path/to/chromedriver', + }, + }, + ]; + await instance?.onPrepare({} as never, capabilities); + expect(capabilities[0]).toEqual({ + 'browserName': 'chrome', + 'browserVersion': '114.0.5735.45', + 'goog:chromeOptions': { + args: [], + binary: 'workspace/my-test-app/dist/my-test-app', + windowTypes: ['app', 'webview'], + }, + 'wdio:chromedriverOptions': { + binary: '/path/to/chromedriver', + }, + 'wdio:electronServiceOptions': {}, + 'wdio:enforceWebDriverClassic': true, + }); + }); + it('should throw an error when appBinaryPath is not specified and no build tool is found', async () => { delete options.appBinaryPath; (getAppBuildInfo as Mock).mockRejectedValueOnce(new Error('b0rk - no build tool found')); @@ -230,7 +287,7 @@ describe('onPrepare', () => { await instance?.onPrepare({} as never, capabilities); expect(capabilities[0]).toEqual({ 'browserName': 'chrome', - 'browserVersion': '114.0.5735.45', + 'browserVersion': '116.0.5845.82', 'goog:chromeOptions': { args: [], binary: 'workspace/my-test-app/dist/my-test-app', @@ -286,7 +343,7 @@ describe('onPrepare', () => { await instance?.onPrepare({} as never, capabilities); expect(capabilities[0]).toEqual({ 'browserName': 'chrome', - 'browserVersion': '114.0.5735.45', + 'browserVersion': '116.0.5845.82', 'goog:chromeOptions': { args: [], binary: 'workspace/my-test-app/dist/my-test-app', @@ -533,7 +590,7 @@ describe('onPrepare', () => { myElectronProject: { capabilities: { browserName: 'electron', - browserVersion: '26.2.2', + browserVersion: '32.0.1', }, }, chrome: { @@ -546,7 +603,7 @@ describe('onPrepare', () => { firstMatch: [], alwaysMatch: { browserName: 'electron', - browserVersion: '25.0.0', + browserVersion: '26.2.2', }, }, }, @@ -561,7 +618,7 @@ describe('onPrepare', () => { myElectronProject: { capabilities: { 'browserName': 'chrome', - 'browserVersion': '116.0.5845.190', + 'browserVersion': '128.0.6613.36', 'goog:chromeOptions': { args: [], binary: 'workspace/my-test-app/dist/my-test-app', @@ -581,7 +638,7 @@ describe('onPrepare', () => { firstMatch: [], alwaysMatch: { 'browserName': 'chrome', - 'browserVersion': '114.0.5735.45', + 'browserVersion': '116.0.5845.190', 'goog:chromeOptions': { args: [], binary: 'workspace/my-test-app/dist/my-test-app', @@ -606,7 +663,7 @@ describe('onPrepare', () => { myElectronProject: { capabilities: { browserName: 'electron', - browserVersion: '26.2.2', + browserVersion: '32.0.1', }, }, }, @@ -621,7 +678,7 @@ describe('onPrepare', () => { firstMatch: [], alwaysMatch: { browserName: 'electron', - browserVersion: '25.0.0', + browserVersion: '26.2.2', }, }, }, @@ -638,7 +695,7 @@ describe('onPrepare', () => { myElectronProject: { capabilities: { 'browserName': 'chrome', - 'browserVersion': '116.0.5845.190', + 'browserVersion': '128.0.6613.36', 'goog:chromeOptions': { args: [], binary: 'workspace/my-test-app/dist/my-test-app', @@ -660,7 +717,7 @@ describe('onPrepare', () => { firstMatch: [], alwaysMatch: { 'browserName': 'chrome', - 'browserVersion': '114.0.5735.45', + 'browserVersion': '116.0.5845.190', 'goog:chromeOptions': { args: [], binary: 'workspace/my-test-app/dist/my-test-app',