Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] console events for electron app #5905

Closed
sirtimid opened this issue Mar 22, 2021 · 12 comments · Fixed by #29322
Closed

[Feature] console events for electron app #5905

sirtimid opened this issue Mar 22, 2021 · 12 comments · Fixed by #29322

Comments

@sirtimid
Copy link

It would be great if we could use the the pluggable logger sink for Electron tests as well. :)

@pavelfeldman
Copy link
Member

We are actually thinking about going the other way around elsewhere. How do you use the sink? Does DEBUG= not work for you?

@sirtimid
Copy link
Author

sirtimid commented Apr 5, 2021

Hey @pavelfeldman I would like to use logger in order to assert things within tests, so I would push the logs in an array and assert that the expected string exists in that array, The DEBUG flag won't help me with this

@sirtimid
Copy link
Author

sirtimid commented Apr 5, 2021

Issue is that currently we can only get the logs from renderer with the console event, I need a way to take the logs from main process as well, spectron has a app.client.getMainProcessLogs() method

@pavelfeldman
Copy link
Member

@sirtimid: would it work if you had something like page.on('console') on the electronApp object?

@sirtimid
Copy link
Author

sirtimid commented Apr 6, 2021

@pavelfeldman yeah, for sure, it would be even better TBH!

@JoelEinbinder JoelEinbinder changed the title Add Logger option to Electron.launch params console events for electron app Apr 6, 2021
@JoelEinbinder JoelEinbinder self-assigned this Apr 6, 2021
@rssk
Copy link

rssk commented Nov 11, 2021

Is there any way to get at electron main logs from the launched process? It seems like otherwise it'd be hard to debug fails on headless tests

@imolorhe
Copy link

I also need this API to retrieve logs from the main process, for the same reasons as @sirtimid. Are there any timelines for this?

@cameron-martin
Copy link

It does seem to collect the stdout and stderr of the launched electron process, but I can't work out how to access them via the public APIs.

@Prinzhorn
Copy link

It does seem to collect the stdout and stderr of the launched electron process, but I can't work out how to access them via the public APIs.

To safe anyone from going through the same rabbit hole I just did, this works with the latest playwright 1.24.1:

const app = await electron.launch({ args: ['main.js'] });

app.process().stdout.on('data', (data) => console.log(`stdout: ${data}`));
app.process().stderr.on('data', (error) => console.log`stderr: ${error}`));

From #13267 (comment) and #13280

@ahmedmukhtar1133
Copy link

@Prinzhorn This doesn't seems to be working in playwright 1.24.2.
This piece of code gives error app.process is not function.

image

@fcastilloec
Copy link

fcastilloec commented Aug 3, 2022

To safe anyone from going through the same rabbit hole I just did, this works with the latest playwright 1.24.1:

const app = await electron.launch({ args: ['main.js'] });

app.process().stdout.on('data', (data) => console.log(`stdout: ${data}`));
app.process().stderr.on('data', (error) => console.log`stderr: ${error}`));

From #13267 (comment) and #13280

Thanks so much for mentioning this new feature! Unfortunately, this doesn't output all stdout or sterr messages from the electron app, only the ones emitted after the app finished loading (from my limited testing, it could be something else). I'm interested in seeing all logs, especially the ones emitted before the did-finish-load event is fired.
As a test, just issue a console.log before you create/load your BrowserWindow and that message is not shown.
So this issue is still not fully fixed.


@Prinzhorn This doesn't seems to be working in playwright 1.24.2. This piece of code gives error app.process is not function.

You can only access the process once the app has finished launching, in other words, you probably forgot to use await when launching your app.

@MatthijsBurgh
Copy link

MatthijsBurgh commented Feb 13, 2023

Is there any progress on this one? Has someone maybe found a workaround?

I experience the same issue as @fcastilloec, where logs before loading are not accessible.

edit: I would also like to get the logs of the renderer process, not only the main process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants