API Reference
Complete API reference for @wdio/dioxus-service.
browser.dioxus API
The following methods are available on the browser.dioxus object when connected to a Dioxus app.
browser.dioxus.execute(script, ...args)
Execute JavaScript code in the Dioxus webview context with access to Dioxus IPC APIs. Requires wdio-dioxus-bridge to be installed and configured in your app.
Parameters:
script(Function | string) - JavaScript code to execute. If a function, receives aDioxusAPIsobject (dx) as the first parameter...args(any[]) - Additional arguments passed to the script
Returns: Promise\<ReturnValue>
DioxusAPIs (dx) object:
interface DioxusAPIs {
invoke: (command: string, args?: unknown) => Promise<unknown>;
log?: {
trace: (msg: string) => void;
debug: (msg: string) => void;
info: (msg: string) => void;
warn: (msg: string) => void;
error: (msg: string) => void;
};
}
Example:
// Execute with destructured DioxusAPIs
const result = await browser.dioxus.execute(({ invoke }) => {
return invoke('get_platform_info');
});
// Execute with full DioxusAPIs object
const greeting = await browser.dioxus.execute(async (dx) => {
return dx.invoke('greet', { name: 'World' });
});
// Execute with arguments
const result = await browser.dioxus.execute(
(dx, name) => dx.invoke('greet', { name }),
'World'
);
// Execute string of code
const href = await browser.dioxus.execute('window.location.href');
Note: Requires wdio-dioxus-bridge to be installed. See Bridge Setup.
browser.dioxus.mock(command)
Mock a specific Dioxus backend command. Returns a DioxusMock object for configuring the mock behavior.
Parameters:
command(string) - Name of the Dioxus command to mock (must match what your app passes toinvoke())
Returns: Promise\<DioxusMock>
Example:
const mock = await browser.dioxus.mock('read_file');
await mock.mockReturnValue('mocked file content');
// Now calling invoke('read_file', ...) returns 'mocked file content'
const content = await browser.dioxus.execute(({ invoke }) => invoke('read_file'));
expect(content).toBe('mocked file content');
browser.dioxus.isMockFunction(fn)
Check if a value is a Dioxus mock function. This is a TypeScript type guard.
Parameters:
fn(unknown) - Value to check
Returns: boolean (type narrows to DioxusMockInstance when true)
Example:
const mock = await browser.dioxus.mock('clipboard_read');
if (browser.dioxus.isMockFunction(mock)) {
// TypeScript knows mock is DioxusMockInstance here
expect(mock.mock.calls).toHaveLength(1);
}
browser.dioxus.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.dioxus.clearAllMocks();
// Clear only clipboard-related mocks
await browser.dioxus.clearAllMocks('clipboard');
browser.dioxus.resetAllMocks(commandPrefix?)
Reset all mocks to their initial state (clears implementations and call history).
Parameters:
commandPrefix(string, optional) - If provided, only mocks with matching prefix are reset
Returns: Promise\<void>
browser.dioxus.restoreAllMocks(commandPrefix?)
Remove all mocks and restore original command implementations.
Parameters:
commandPrefix(string, optional) - If provided, only mocks with matching prefix are restored
Returns: Promise\<void>
Example:
await browser.dioxus.restoreAllMocks();
// Commands now call the real Dioxus backend again
browser.dioxus.switchWindow(label)
Switch the active Dioxus window for subsequent operations. Changes the window that browser.dioxus.execute() and other Dioxus-specific operations target.
Parameters:
label(string) - The window label to switch to (e.g.,'main','settings')
Returns: Promise\<void>
Example:
// Switch to the settings window
await browser.dioxus.switchWindow('settings');
// Now executes in the settings window context
const data = await browser.dioxus.execute(({ invoke }) => invoke('get_settings'));
// Switch back to main window
await browser.dioxus.switchWindow('main');
Note: The window label must exist in your Dioxus app. Use browser.dioxus.listWindows() to get available labels.
browser.dioxus.listWindows()
Get a list of all available Dioxus window labels in the application.
Returns: Promise\<string[]>
Example:
const windows = await browser.dioxus.listWindows();
console.log(windows); // ['main', 'settings', 'dialog']
browser.dioxus.triggerDeeplink(url)
Trigger a deeplink to the Dioxus application for testing protocol handlers. Uses platform-specific commands (open on macOS, xdg-open on Linux, cmd /c start on Windows).
Parameters:
url(string) - The deeplink URL to trigger (e.g.,'myapp://open?file=test.txt')
Returns: Promise\<void>
Example:
await browser.dioxus.triggerDeeplink('myapp://open?file=test.txt');
await browser.waitUntil(async () => {
const openedFile = await browser.dioxus.execute(() => {
return globalThis.lastOpenedFile;
});
return openedFile === 'test.txt';
});
See Deeplink Testing for the full usage guide.
Note:
emitEventis deferred to v1.1.
DioxusMock Interface
When you call browser.dioxus.mock(command), you receive a DioxusMock object with these methods:
mockImplementation(fn)
Set a custom implementation function for the mock.
Returns: Promise\<DioxusMock>
Example:
const mock = await browser.dioxus.mock('calculate');
await mock.mockImplementation(async (args) => args.x + args.y);
const result = await browser.dioxus.execute(({ invoke }) => invoke('calculate', { x: 5, y: 3 }));
// result === 8