playwright-community / playwright-go

Playwright for Go a browser automation library to control Chromium, Firefox and WebKit with a single API.
https://playwright-community.github.io/playwright-go/
MIT License
1.94k stars 145 forks source link

Is there a way to not close the browser window when the test is done? #334

Open daniel-abramov opened 1 year ago

daniel-abramov commented 1 year ago

I'm using playwright-go in the following way. I create 10 contexts. Each context creates its page, performs a log-in operation in the app, and then joins chat rooms with fake audio and video devices that I've configured with Chromium flags. The app continues to run until I send a SIGTERM to it.

After some tests, I've noticed that the test clients that are being created in such a way do disappear shortly after being started (despite the test application with playwright running).

That was a bummer as I expected the Chromium instances to remain open until the app ended or the playwright, context, or page are closed.

I removed the headless flag to see what happens and noticed that the Chromium windows just get closed by the playwright for some unknown reason.

I tried to work with the persistent context to workaround it, but it did not change anything, unfortunately.

marc136 commented 1 year ago

Hi @daniel-abramov, not sure if this is available in the go bindings, because I couldn't geht playwright to run.

But with node.js, I use the page pause API for this purpose.

It seems to exist in the go API as well: https://github.com/playwright-community/playwright-go/blob/989def6e23dddd81011d3e0af65004402bc0ae1f/generated-interfaces.go#L1647

daniel-abramov commented 1 year ago

Thanks, @marc136. Yeah, I've tried Pause() and also different wait-functions, but unfortunately they did not have the intended effect. The Pause() paused the execution of the JavaScript (which I did not want as I needed the page to continue execution and reaction to the incoming events). And the wait functions did not seem to have any effect at all (Playwright kept closing windows if they were in a waiting state). I suppose it's either some sort of a bug or expected behavior that might have a simple solution that I'm just not aware of 🙂

I went for a workaround by rewriting it in Rust using rust-headless-chrome that relies upon Chrome DevTools Protocol, so its API surface is very similar to Playwright. Surprisingly, it does not exhibit the same issue and worked just fine for my use case.