spectron: javascript error: Cannot convert undefined or null to object
Hey, after updating electron to v10 and spectron to v12 I’ve started having issues with running my test suite. So I started debugging by creating a single test with code taken from spectron’s readme. And when trying to run this test (I’m using Jest by the way) I get this error:
javascript error: javascript error: Cannot convert undefined or null to object
(Session info: chrome=85.0.4183.98)
at getErrorFromResponseBody (node_modules/webdriver/build/utils.js:121:10)
at WebDriverRequest._request (node_modules/webdriver/build/request.js:149:56)
at Browser.wrapCommandFn (node_modules/@wdio/utils/build/shim.js:74:23)
at Browser.wrapCommandFn (node_modules/@wdio/utils/build/shim.js:74:23)
Application window launches however, the test fails
- Node: v14.10.1
- spectron: 12.0.0
- electron: v10.1.2
- chromedriver: 85.0.4183.98
About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 25
- Comments: 23
Tracked this one down I think.
Its an error from https://github.com/electron-userland/spectron/blob/1510a9beddb64ca3630c143ccdc15466e17b40f5/lib/api.js whose stack trace gets eaton by the bootstrap process.
Running it manually, we find the error is thrown here because
electron.remoteis undefined: https://github.com/electron-userland/spectron/blob/1510a9beddb64ca3630c143ccdc15466e17b40f5/lib/api.js#L141As of Electron 10
enableRemoteModuledefaults tofalse. It will be removed in v14. https://github.com/electron/electron/blob/master/docs/breaking-changes.md#default-changed-enableremotemodule-defaults-to-falseThe fix for me was to explicitly enable it when creating my window in
webPreferences:This should be updated in the getting started docs, and Spectron should migrate away from electron.remote if that’s not already planned 🙂
I have seen both of these. I have tried these two fixes but no luck there.
https://github.com/electron-userland/spectron/issues/174 https://github.com/electron-userland/spectron/issues/254
Any updates on this?
First time I try to use Spectron - and using the readme example - I do get the same error as others have mentionned:
@amiller-gh This is correct. Remote module was missing. I enable it during tests now.
This didn’t solve it for me - I actually already tried this a few months ago.