Plugin Setup
Overview
The tauri-plugin-wdio is a required Tauri plugin that enables WebdriverIO testing of Tauri applications. It provides:
- Execute API - Run JavaScript code from tests with access to Tauri APIs
- 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
Two WDIO Plugins
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 | Only for embedded provider |
When You Need Each
-
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
- Auto-detected on macOS; signal via
TAURI_WEBDRIVER_PORTon Windows/Linux
Why Is It Required?
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.
What Works Without the Plugin
Only basic WebDriver operations work without the plugin:
- Element interactions (click, type, etc.)
- Navigation and page access
- Basic WebDriver commands
What Requires the Plugin
All advanced testing features require the plugin:
- ✅
browser.tauri.execute()- Execute JavaScript with Tauri APIs - ✅
browser.tauri.mock()- Mock backend commands - ✅ All mocking operations
- ✅ Console log capture
- ✅ Backend log forwarding
Installation Steps
Step 1: Add Cargo Dependency
Add the plugin to your src-tauri/Cargo.toml:
[dependencies]
tauri = { version = "2", features = ["..your other features.."] }
tauri-plugin-wdio = "1"
Step 2: Register Plugin in Rust
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.
Step 3: Add Tauri Permissions
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-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.
Step 4: Enable Global Tauri API
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"]
}
}
}
Step 5: Import Frontend Plugin
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';
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
Step 6: Build and Verify
Build your Tauri app:
cd src-tauri
cargo build --release
The build should complete successfully without errors about the plugin.
Verifying the Plugin Installation
Method 1: Check Browser Console
After starting your test session, the plugin will log initialization messages:
[WDIO Plugin] Initializing...
[WDIO Plugin] Successfully initialized
Method 2: Test Plugin Availability
In a test, check if the plugin is available:
it('should have plugin available', async () => {
const available = await browser.tauri.isTauriApiAvailable?.();
expect(available).toBe(true);
});
Method 3: Try Execute API
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();
});
Troubleshooting Plugin Issues
"Tauri plugin not available" Error
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.
"window.wdioTauri is undefined" Error
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);
});
Mocking Doesn't Work
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');
Plugin Compilation Errors
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 --release -
Check Tauri version compatibility
- tauri-plugin-wdio requires Tauri v2.0+
- If you're on Tauri v1, this plugin won't work
-
Check dependency versions
tauri = { version = "2", ... }
tauri-plugin-wdio = "1"