electron-userland / spectron

DEPRECATED: 🔎 Test Electron apps using ChromeDriver
http://electronjs.org/spectron
MIT License
1.68k stars 229 forks source link

Switch from v10 to v11, now `getRenderProcessLogs()` only returns warnings and errors #723

Open dooglio opened 4 years ago

dooglio commented 4 years ago

After migrating to Electron 9, and thus to Spectron 11.x, now when I call getRenderProcessLogs() the lowest level of log I get is WARNING from my app. For Spectron 10.x, I always got INFO level logs.

I made sure the --verbose flag is turned on for chrome-driver options, and the webdriver log level defaults toinfo. There is a loggingPrefs option in the desiredCapabilities in webdriver, but I cannot find a way to set this from Spectron.

The upshot is that the internal getLogs('browser') now only returns warnings and critical level logs. console.log() logs no longer show up.

I suspect this is due to the migration internally from webdriverio 4.x --> 6.x.

ali-rantakari commented 3 years ago

The way to configure the Chrome WebDriver (e.g. to ask it to include info-level logs) seems to be to pass an object like the following under capabilities in the options object passed to WebDriver.remote():

'goog:loggingPrefs': {
  browser: 'INFO',
  driver: 'INFO',
  server: 'INFO',
  client: 'INFO'
}

Even though Spectron's API offers a way to amend the options sent to webdriverio (via webdriverOptions), unfortunately they are applied via Object.assign() to the top level options object, which means that you can only assign values for top-level keys, overwriting any existing values set by the library. In this case we would need to add a new key+value to options.capabilities (namely, goog:loggingPrefs), while retaining existing ones (e.g. the goog:chromeOptions set by Spectron).

Relevant sources: https://github.com/electron-userland/spectron/blob/c4fe27ec7840ea0468a46ec7ec1b5d69a124b017/lib/application.js#L219