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);
}