tauri-plugin-phyto
A Tauri plugin that runs an HTTP automation server inside a Tauri app so Phyto (an end-to-end testing framework for Tauri) can drive it.
What it does
When the plugin is initialized, it:
- Starts an HTTP server on port
9876(configurable) bound to0.0.0.0. - Polls the webview until it has navigated past
about:blank, the Tauri IPC bridge is available, and the in-page Phyto harness (injected by@phyto/vite-plugin) has loaded. - Forwards
POST /commandrequests to the in-page harness viawindow.__phyto_harness__.execute(), then sends the structured result back over HTTP. - Exposes
GET /healthfor readiness probing.
The plugin is intended for test builds only. It listens on 0.0.0.0 and
runs arbitrary JavaScript supplied by the test driver — do not enable it in
production builds.
Usage
The plugin is intended for test builds only. The recommended integration
puts everything behind a Cargo feature (called e2e by convention) so
production builds neither compile the plugin nor reference its capability.
1. Declare the feature
In src-tauri/Cargo.toml:
[]
= ["tauri-plugin-phyto"]
[]
= { = "0.1", = true }
[]
= { = "0.1", = false, = ["build"] }
The [build-dependencies] entry pulls in just the build helper module
(std-only, no Tauri tree on the host compile).
2. Sync the capability in build.rs
Tauri capabilities are filesystem-scanned at build time and tauri-build
rejects any capability that references an unregistered plugin. The
sync_capability helper writes capabilities/phyto.json when the e2e
feature is on and deletes it when off — so the same source tree builds
cleanly in both modes:
For multi-window apps or a non-e2e feature name, use the builder form:
new
.feature
.windows
.run;
3. Register the plugin
Gate the plugin registration on the same feature in your Tauri builder:
Then build with cargo build --features e2e for test runs and without
the feature for production. The capability file is created/removed
automatically; you should not commit it to source control.
Configuration
use PhytoConfig;
default
.plugin
| Field | Default | Description |
|---|---|---|
| port | 9876 | Port the HTTP automation server binds to. |
How it fits together
tauri-plugin-phyto is the in-app server half of Phyto. On the other side:
@phyto/vite-plugin(npm) injects the in-page harness into your app's build output during test runs.@phyto/driver-tauri(npm) is the Node-side driver that issuesclick/type/wait-forcommands over this plugin's HTTP socket.phyto(npm) is the test-authoring DSL.@phyto/cli(npm) is the orchestrator that builds the app, discovers tests, and runs each one against a fresh app instance.
See the top-level Phyto README for the full picture.
Protocol version
The plugin and driver negotiate a PROTOCOL_VERSION integer at startup. If
they disagree, the CLI exits with a clear error naming the mismatched
component. Bump this version on breaking wire-format changes only.