The tauri-plugin-wdio is a required Tauri plugin that enables WebdriverIO testing of Tauri applications. It provides:
- Execute API - Run JavaScript in the app's frontend from tests, and call its commands
- Mocking Support - Mock Tauri backend commands for isolated testing
- Log Forwarding - Capture console logs from both frontend and backend
- Invoke Interception - Enable mocking without backend command modifications
There are two Tauri plugins for WebdriverIO testing:
| Plugin | Package | Purpose | Required |
|---|---|---|---|
tauri-plugin-wdio |
Rust + JS | Execute API, mocking, log forwarding | Yes |
tauri-plugin-wdio-webdriver |
Rust only | Embedded WebDriver server | For embedded, the default |
-
tauri-plugin-wdio- Always required for:- Executing JavaScript in the frontend (
browser.tauri.execute()) - Mocking Tauri commands (
browser.tauri.mock()) - Capturing frontend and backend logs
- Executing JavaScript in the frontend (
-
tauri-plugin-wdio-webdriver- Required when using the embedded driver provider:- Provides built-in WebDriver HTTP server
- Eliminates need for external tauri-driver
- Enables native macOS testing without CrabNebula
- Used whenever the
embeddedprovider is active — the default on every platform whendriverProvideris unset
The @wdio/tauri-service explicitly checks for the plugin and will fail if it's not available:
Error: Tauri plugin not available. Make sure @wdio/tauri-plugin is installed and registered in your Tauri app.
Only basic WebDriver operations work without the plugin:
- Element interactions (click, type, etc.)
- Navigation and page access
- Basic WebDriver commands
All advanced testing features require the plugin:
- ✅
browser.tauri.execute()- Run JavaScript in the frontend and call commands - ✅
browser.tauri.mock()- Mock backend commands - ✅ All mocking operations
- ✅ Console log capture
- ✅ Backend log forwarding
Add the plugin to your src-tauri/Cargo.toml:
[dependencies]
tauri = { version = "2", features = ["..your other features.."] }
tauri-plugin-wdio = "1"Add the plugin initialization to your src-tauri/src/main.rs:
fn main() {
tauri::Builder::default()
.plugin(tauri_plugin_wdio::init()) // Add this line
.run(tauri::generate_context!())
.expect("error while running tauri application");
}Place it anywhere in the plugin chain - typically after other plugins.
The plugin requires WDIO permissions in your capabilities. Edit src-tauri/capabilities/default.json:
{
"identifier": "default",
"windows": [
"main"
],
"permissions": [
"core:default",
"core:window:default",
"wdio:default"
]
}Or use individual permissions if you prefer fine-grained control:
{
"permissions": [
"core:default",
"core:window:default",
"wdio:allow-execute",
"wdio:allow-emit-deep-link",
"wdio:allow-log-frontend",
"wdio:allow-debug-plugin",
"wdio:allow-get-active-window-label",
"wdio:allow-get-window-states",
"wdio:allow-list-windows"
]
}Note: Mocking is implemented entirely on the JavaScript side via invoke interception (
window.__wdio_mocks__), so there are nowdio:allow-set-mock/allow-clear-mocksstyle permissions to configure.
Make sure withGlobalTauri is enabled in src-tauri/tauri.conf.json:
{
"app": {
"withGlobalTauri": true,
"windows": [
{
"title": "My App",
"width": 800,
"height": 600
}
],
"security": {
"capabilities": [
"default"
]
}
}
}Import the frontend plugin in your main frontend entry file (usually index.html or main.ts):
In HTML:
<script type="module">
import '@wdio/tauri-plugin';
</script>In TypeScript/JavaScript:
import '@wdio/tauri-plugin';@wdio/tauri-plugin uses your app's @tauri-apps/api (2.10 or later) rather than bringing its own copy.
This import must happen before your tests run. The plugin auto-initializes on import and sets up:
window.wdioTauriAPI- Console forwarding
- Invoke interception for mocking
- Event listeners for backend logs
Build a debug binary to test:
npm run tauri build -- --debugThe build should complete successfully without errors about the plugin.
After starting your test session, the plugin will log initialization messages:
[WDIO Plugin] Initializing...
[WDIO Plugin] Successfully initialized
The execute API will work if the plugin is properly installed:
it('should execute JavaScript', async () => {
const result = await browser.tauri.execute(() => {
return window.location.href;
});
expect(result).toBeDefined();
});This means the plugin is not detected. Check:
-
Plugin registered in Rust
.plugin(tauri_plugin_wdio::init())
-
Frontend import present
import '@wdio/tauri-plugin';
-
withGlobalTaurienabled{ "app": { "withGlobalTauri": true } } -
Permissions configured Check that
"wdio:default"is in your capabilities permissions.
The frontend plugin didn't initialize. Make sure:
- The import statement is in your main entry point, before tests run
- You're not running in an iframe or separate context
- The app has time to initialize (add a small delay if needed):
it('should have wdioTauri', async () => {
// Give plugin time to initialize
await browser.pause(500);
const hasPlugin = 'wdioTauri' in window;
expect(hasPlugin).toBe(true);
});Make sure:
- Plugin is installed and available (see verification methods above)
- You're using
browser.tauri.mock(), not trying to mock directly - The mock is set up before calling the command:
// ✅ Correct
const mock = await browser.tauri.mock('my_command');
await mock.mockReturnValue('test');
await browser.tauri.execute(({ core }) => core.invoke('my_command'));
// ❌ Wrong - mock set up after calling command
await browser.tauri.execute(({ core }) => core.invoke('my_command'));
const mock = await browser.tauri.mock('my_command');- The app's CSP allows Tauri's IPC:
connect-srcincludesipc:andhttp://ipc.localhost. If it doesn't, Tauri falls back to itspostMessageIPC, and mocks no longer see the commands the app invokes.
If you get Rust compilation errors:
-
Ensure Rust toolchain is up to date
rustup update
-
Clear Cargo cache
cd src-tauri cargo clean cargo build -
Check Tauri version compatibility
- tauri-plugin-wdio requires Tauri v2.10+
- If you're on Tauri v1, this plugin won't work
-
Check dependency versions
tauri = { version = "2", ... } tauri-plugin-wdio = "1"
The plugin consists of two parts:
-
Rust Backend (
packages/tauri-plugin/src/)- Provides Tauri commands:
execute,log_frontend,debug_plugin - Handles script execution via
window.eval() - Manages result serialization
- Provides Tauri commands:
-
Frontend JavaScript (
packages/tauri-plugin/guest-js/)- Auto-initializes on import
- Exposes
window.wdioTauriAPI - Routes the commands the app invokes to
browser.tauri.mock()mocks - Forwards console logs to Tauri logger
When you import @wdio/tauri-plugin:
- Plugin code loads and detects Tauri APIs
- Sets up console forwarding
- Sets up invoke interception for mocking
- Registers event listeners for backend logs
- Exposes
window.wdioTauriobject - On page unload, cleans up listeners and timers
The wdio:default permission includes every plugin command:
wdio:allow-execute- Execute JavaScript in frontend contextwdio:allow-emit-deep-link- Emit a deep link fortriggerDeeplink()wdio:allow-log-frontend- Forward frontend logswdio:allow-debug-plugin- Debug plugin statewdio:allow-get-active-window-label- Get active window labelwdio:allow-get-window-states- Get window stateswdio:allow-list-windows- List windows
Mocking is implemented entirely on the JavaScript side via invoke interception, so there are no mock-related Rust permissions.
If you want a smaller surface, you can grant a subset — wdio:allow-execute alone is enough to run scripts and use the mocking API:
{
"permissions": [
"wdio:allow-execute"
]
}No, the plugin is test-only. For production builds:
-
Conditionally register the plugin
fn main() { let mut builder = tauri::Builder::default(); #[cfg(debug_assertions)] { builder = builder.plugin(tauri_plugin_wdio::init()); } builder .run(tauri::generate_context!()) .expect("error while running tauri application"); }
-
Or use feature flags
[features] wdio = ["dep:tauri-plugin-wdio"] [dependencies] tauri-plugin-wdio = { version = "1", optional = true }
fn main() { let mut builder = tauri::Builder::default(); #[cfg(feature = "wdio")] { builder = builder.plugin(tauri_plugin_wdio::init()); } builder .run(tauri::generate_context!()) .expect("error while running tauri application"); }
-
Build release without the plugin
cargo build --release
The plugin:
- Only accepts code from WebdriverIO service (not from page scripts)
- Cannot access browser or system permissions without being granted
- Is disabled in production builds
- Requires explicit
wdio:permissions in capabilities
Once the plugin is installed and verified:
- Read Quick Start for minimal test setup
- See API Reference for available functions
- Check Usage Examples for testing patterns
- View Configuration for service options
This plugin embeds a W3C WebDriver HTTP server directly in your Tauri application. The default embedded provider needs it; the external and crabnebula providers don't.
In builds that register it, the plugin also adds window.__wdio_element_events to every page and frame: the helpers its element and key commands call. With them come capture blur and focusout listeners on the window, so a field the plugin typed into fires its change before the page's listeners see it lose focus, as in a browser. Listeners added before the plugin's still run first: those from an earlier init script, and, where the plugin's init script didn't run, those the page adds before a command installs the helpers. After document.open(), which removes the plugin's listeners, all the page's listeners run first.
- Tauri v2.10+
- The
embeddedprovider in use (the default; or setdriverProvider: 'embedded'explicitly)
[dependencies]
tauri-plugin-wdio-webdriver = "1"The next step registers it only in debug builds, so release builds never start its WebDriver server.
fn main() {
let builder = tauri::Builder::default();
#[cfg(debug_assertions)]
let builder = builder.plugin(tauri_plugin_wdio_webdriver::init());
builder
.run(tauri::generate_context!())
.expect("error while running tauri application");
}{
"identifier": "default",
"windows": [
"main"
],
"permissions": [
"core:default",
"core:window:default",
"wdio-webdriver:default"
]
}The
wdio-webdriver:defaultset currently grants no IPC permissions — the plugin is an in-process HTTP server, not a command surface — but listing it ensures Tauri loads the plugin's ACL manifest.
The embedded WebDriver server runs on port 4445 by default. To customize:
// In wdio.conf.ts
services: [
[
'@wdio/tauri-service',
{
driverProvider: 'embedded',
embeddedPort: 4445, // Optional, defaults to 4445
},
],
];Or set the port via environment variable:
TAURI_WEBDRIVER_PORT=4445 npx wdio run wdio.conf.ts- The service spawns your Tauri app with
TAURI_WEBDRIVER_PORTenvironment variable - The app starts an HTTP WebDriver server on that port
- WebdriverIO connects directly to that port (no tauri-driver intermediary)
- On test completion, the service terminates the app
| Aspect | External Driver (external/crabnebula) | Embedded Server |
|---|---|---|
| Architecture | Separate driver process | HTTP server in-app |
| macOS support | Requires CrabNebula | Native |
| Setup complexity | Higher (driver installation) | Lower (no external deps) |
| Port management | Service manages | Service + app coordinate |