spectron icon indicating copy to clipboard operation
spectron copied to clipboard

browserWindow is undefined

Open Ladvace opened this issue 4 years ago • 9 comments

app.browserWindow return property of undefined, seems that browserWindow doesn't exist in app

Ladvace avatar Oct 07 '20 19:10 Ladvace

I do face the same issue.

Manisha-kannankot avatar Oct 13 '20 19:10 Manisha-kannankot

With which version?

I am using Electron 10.0.1 and it works correclty.

jesusiglesias avatar Oct 19 '20 08:10 jesusiglesias

I'm using ^8.5.0 version of electron

Ladvace avatar Oct 19 '20 09:10 Ladvace

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 | });

MikeMor-fr avatar Oct 21 '20 10:10 MikeMor-fr

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 | });

MikeMor-fr avatar Oct 21 '20 10:10 MikeMor-fr

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, }, });

MikeMor-fr avatar Oct 21 '20 13:10 MikeMor-fr

I already have it but it doesn't work

Ladvace avatar Oct 22 '20 20:10 Ladvace

@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

jesusiglesias avatar Nov 03 '20 08:11 jesusiglesias

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...

mithom avatar Feb 24 '21 16:02 mithom