API Reference
Complete API reference for @wdio/tauri-service.
browser.tauri API
The following methods are available on the browser.tauri object when connected to a Tauri app.
browser.tauri.execute(script, ...args)
Execute JavaScript code in the Tauri frontend context with access to Tauri APIs. Requires tauri-plugin-wdio to be installed and configured.
Parameters:
script(Function | string) - JavaScript code to execute. If a function, receives Tauri APIs as the first parameter...args(any[]) - Additional arguments passed to the script
Returns: Promise\<ReturnValue>
Example:
// Execute with destructured Tauri APIs
const result = await browser.tauri.execute(({ core }) => {
return core.invoke('get_platform_info');
});
// Execute with full Tauri APIs object
const version = await browser.tauri.execute(async (tauri) => {
return tauri.app?.getVersion();
});
// Execute with arguments
const result = await browser.tauri.execute(
(tauri, name) => tauri.core.invoke('greet', { name }),
'World'
);
// Execute string of code
const result = await browser.tauri.execute('window.location.href');
Note: Requires tauri-plugin-wdio to be installed. See Plugin Setup.
browser.tauri.mock(command)
Mock a specific Tauri backend command. Returns a TauriMock object for configuring the mock behavior.
Parameters:
command(string) - Name of the Tauri command to mock
Returns: Promise\<TauriMock>
Example:
const mock = await browser.tauri.mock('read_file');
await mock.mockReturnValue('mocked file content');
// Now calling invoke('read_file', ...) returns 'mocked file content'
const content = await browser.tauri.execute(({ core }) => core.invoke('read_file'));
expect(content).toBe('mocked file content');
browser.tauri.isMockFunction(fn)
Check if a value is a Tauri mock function. This is a TypeScript type guard.
Parameters:
fn(unknown) - Value to check
Returns: boolean (type narrows to TauriMockInstance when true)
Example:
const mock = await browser.tauri.mock('clipboard_read');
if (browser.tauri.isMockFunction(mock)) {
// TypeScript knows mock is TauriMockInstance here
expect(mock.mock.calls).toHaveLength(1);
}
browser.tauri.clearAllMocks(commandPrefix?)
Clear all mock call history and reset results, but keep the mock implementations in place.
Parameters:
commandPrefix(string, optional) - If provided, only mocks with command names starting with this prefix will be cleared
Returns: Promise<void>
Example:
// Clear all mocks
await browser.tauri.clearAllMocks();
// Clear only clipboard-related mocks
await browser.tauri.clearAllMocks('clipboard');