Skip to content

Commit 2dcdcf6

Browse files
committed
feat: support electron v15
1 parent 5e3402c commit 2dcdcf6

File tree

19 files changed

+8712
-1794
lines changed

19 files changed

+8712
-1794
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ For given versions of Electron you must depend on a very specific version range
3636
| `^11.0.0` | `^13.0.0`|
3737
| `^12.0.0` | `^14.0.0`|
3838
| `^13.0.0` | `^15.0.0`|
39+
| `^15.0.0` | `^17.0.0`|
3940

4041
Learn more from [this presentation](https://speakerdeck.com/kevinsawicki/testing-your-electron-apps-with-chromedriver).
4142

lib/api.js

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ Api.prototype.loadApi = function () {
7979
);
8080
}
8181
const electron = window[requireName]('electron');
82+
electron.remote = window[requireName]('@electron/remote');
8283
const process = window[requireName]('process');
8384

8485
const api = {
@@ -350,9 +351,8 @@ Api.prototype.addCapturePageSupport = function () {
350351
async function (rect, requireName, done) {
351352
const args = [];
352353
if (rect != null) args.push(rect);
353-
const browserWindow = window[requireName](
354-
'electron'
355-
).remote.getCurrentWindow();
354+
const browserWindow =
355+
window[requireName]('@electron/remote').getCurrentWindow();
356356
const image = await browserWindow.capturePage.apply(
357357
browserWindow,
358358
args
@@ -413,9 +413,8 @@ Api.prototype.addSavePageSupport = function () {
413413
app.client.addCommand('webContents.savePage', function (fullPath, saveType) {
414414
return this.executeAsync(
415415
async function (fullPath, saveType, requireName, done) {
416-
const webContents = window[requireName](
417-
'electron'
418-
).remote.getCurrentWebContents();
416+
const webContents =
417+
window[requireName]('@electron/remote').getCurrentWebContents();
419418
await webContents.savePage(fullPath, saveType);
420419
done();
421420
},
@@ -445,9 +444,8 @@ Api.prototype.addExecuteJavaScriptSupport = function () {
445444
function (code, useGesture) {
446445
return this.executeAsync(
447446
async function (code, useGesture, requireName, done) {
448-
const webContents = window[requireName](
449-
'electron'
450-
).remote.getCurrentWebContents();
447+
const webContents =
448+
window[requireName]('@electron/remote').getCurrentWebContents();
451449
const result = await webContents.executeJavaScript(code, useGesture);
452450
done(result);
453451
},
@@ -538,7 +536,7 @@ function callRenderApi(moduleName, api, args, requireName) {
538536
}
539537

540538
function callMainApi(moduleName, api, args, requireName) {
541-
let module = window[requireName]('electron').remote;
539+
let module = window[requireName]('@electron/remote');
542540
if (moduleName) {
543541
module = module[moduleName];
544542
}
@@ -550,16 +548,14 @@ function callMainApi(moduleName, api, args, requireName) {
550548
}
551549

552550
function callWebContentsApi(name, args, requireName) {
553-
const webContents = window[requireName](
554-
'electron'
555-
).remote.getCurrentWebContents();
551+
const webContents =
552+
window[requireName]('@electron/remote').getCurrentWebContents();
556553
return webContents[name].apply(webContents, args);
557554
}
558555

559556
function callBrowserWindowApi(name, args, requireName) {
560-
const browserWindow = window[requireName](
561-
'electron'
562-
).remote.getCurrentWindow();
557+
const browserWindow =
558+
window[requireName]('@electron/remote').getCurrentWindow();
563559
return browserWindow[name].apply(browserWindow, args);
564560
}
565561

lib/spectron.d.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,7 @@ declare module 'spectron' {
6363
}[];
6464
}
6565

66-
export interface SpectronClient extends WebdriverIO.BrowserObject {
67-
/**
68-
* Focus a window using its title or URL.
69-
* <webview> tags can also be focused as a separate window.
70-
*/
71-
switchWindow(urlOrTitleToMatch: string): Promise<void>;
72-
66+
export interface SpectronClient extends WebdriverIO.Browser<'async'> {
7367
/**
7468
* Wait until the window is no longer loading.
7569
* Takes an optional timeout in milliseconds that defaults to 5000.
@@ -261,7 +255,7 @@ declare module 'spectron' {
261255
* Each Electron module is exposed as a property on the electron property so you can
262256
* think of it as an alias for require('electron') from within your app.
263257
*/
264-
electron: Electron.RemoteMainInterface;
258+
electron: typeof Electron;
265259
/**
266260
* The browserWindow property is an alias for require('electron').remote.getCurrentWindow().
267261
* It provides you access to the current BrowserWindow and contains all the APIs.

0 commit comments

Comments
 (0)