microsoft / playwright-java

Java version of the Playwright testing and automation library
https://playwright.dev/java/
Apache License 2.0
1.13k stars 205 forks source link

[Feature]: Add method to retrieve the wsEndpoint of a browser launched with Playwright #1572

Closed ramsestom closed 4 months ago

ramsestom commented 5 months ago

🚀 Feature Request

Could you add a method to retrieve the wsEndpoint of any CDP compatible Browser launched with playwright? Currently this is only accessible on the browserserver class https://playwright.dev/docs/api/class-browserserver which only exists for node.js (hence not available in the java, python, and .net API) It would be usefull if the wsEndpoint could be exposed as a property of the CDPSession Class for exemple (as each API langage version has a newBrowserCDPSession method). Or directly as a property of the Browser Class. This would allow to connect to a browser launched with playwright with any other testing framework supporting the CDP which is currently not feasible (only the reverse is. i.e. connect with playwright over CDP to a browser launched outside of playwright)

Example

No response

Motivation

Currently, if we want to mix different testing frameworks (playwright, selenium, pupeteer,...), playwright can't be used as the first framework used in the pipeline (the one who will launch the browser) as it do not allow to know the CDP wsEndpoint of browsers launched with it. Hence the browser always have to be launched outside of playwright (by another framework or directly) and playwright attached to it afterward. This increases the risk of launching a browser with args that will not be optimal for playwright and limit the possibilities for easily integrating playwright into a preexisting testing pipeline (for a step by step transition of a complex testing pipeline to full playwright for example)

mxschmitt commented 5 months ago

Playwright under the hood does not use WebSockets when connecting to a browser, so there is no way of exposing them. If you want to create a remote connection via Playwright's connection protocol (launchServer/connect) (which is different to CDP) we recommend starting a server either with Node.js or via the CLI and then connecting to it.

If you want to get the CDP port, we recommend launching the browser outside of Playwright and then connecting to it via CDP.

mxschmitt commented 4 months ago

Closing as per above.