spectron
spectron copied to clipboard
browserWindow is undefined
app.browserWindow
return property of undefined, seems that browserWindow
doesn't exist in app
I do face the same issue.
With which version?
I am using Electron 10.0.1 and it works correclty.
I'm using ^8.5.0
version of electron
I am facing the same issue. electron version : ^10.1.3 spectron : ^12.0.0
TypeError: Cannot read property 'isDevToolsOpened' of undefined
49 |
50 | it('Await/Asyn - Devtools fermé', async () => {
> 51 | const isOpen = await app.webContents.isDevToolsOpened();
| ^
52 | return expect(isOpen).toBeTruthy();
53 | });
54 | });
Sorry, I publish for webContents, but same for browserWindow
TypeError: Cannot read property 'isMaximized' of undefined
49 |
50 | it('Await/Asyn - Plein ecran', async () => {
> 51 | const isFull = await app.browserWindow.isMaximized();
| ^
52 | return expect(isFull).toBeTruthy();
53 | });
54 | });
I solved this issue by doing this by adding webPreferences option in my electron.js file :
mainWindow = new BrowserWindow({ width: 900, height: 680, webPreferences: { nodeIntegration: true, enableRemoteModule: true, }, });
I already have it but it doesn't work
@Ladvace You can log this property (nodeIntegration) when your testing application starts and check the value later on. It must be to true. If the value is false, then you have to be sure you set up this value to true when you define your new BrowserWindow([options])
in development code. Important! Spectron checks the first window and enables or disables access to all native APIs based on it.
From Electron 5, this property is set up to false by default as the documentation indicates:
nodeIntegration Boolean (optional) - Whether node integration is enabled. Default is false.
Links:
-
https://www.electronjs.org/docs/tutorial/security
-
https://github.com/electron-userland/spectron/issues/571
but setting this property to true for tests and false in production would allow for serious bugs not to be noticed by the tests. having different configurations like this defeat the whole purpose of tests...