jonhoo / fantoccini

A high-level API for programmatically interacting with web pages through WebDriver.
Apache License 2.0
1.68k stars 125 forks source link

Testing of client&server-side Rust interaction #217

Open JohnScience opened 1 year ago

JohnScience commented 1 year ago

Hi, I have a Tauri app where the frontend is written using wasm_bindgen and built with wasm_pack. This means that I have Rust both on the frontend (with HTML&CSS) and on the backend.

For best performance of transmission of large arrays, I have to use tauri::Builder::register_uri_scheme_protocol() as suggested in this issue.

I want to ensure that the data that I encode as Vec<u8> body on the backend can be correctly decoded on the frontend with ReadableStreamDefaultReader ( MDN | web_sys ) and ReadableStreamBYOBReader ( MDN | web_sys ), if the latter is available.

Can I somehow leverage fantoccini for this purpose? The great challenge is that the Rust for the frontend and for the backend is compiled for different compile targets.

Essentially, I would like to mock the connection to a server and provide immediately-loaded Rust. I believe that it's almost certainly too much of a request for too much of a niche problem but I acknowledge that it would be useful for me.

stevepryde commented 1 year ago

Fantoccini interacts with the browser via the webdriver protocol. For Tauri this would mean connecting the chromedriver to the webview via the chrome debugging port (for chrome browsers), and using fantoccini to send commands to chromedriver.

This means you can navigate to various client URLs, inspect the contents of the page, execute javascript, click elements, etc.

If that helps with what you need, then fantoccini can probably help you. However, it currently cannot inspect the network traffic in either direction (i.e. what you see in the Network tab in the browser devtools).

For that, you can use the Chrome Devtools Protocol (CDP), which fantoccini does support but doesn't implement. This does provide access to the network requests etc. See here for more info: https://chromedevtools.github.io/devtools-protocol/ If you need to use CDP, you can take a look at thirtyfour, which I maintain. It's built on top of fantoccini. Support for CDP is very basic but it may be enough to get you started. Start here.

However, if you are trying to interact with the Rust parts of Tauri, or the frontend code itself, fantoccini doesn't really do that.