Skip to content
Tutorials Center
My learning

Topics

Lesson 34 of 39 ยท Testing and Updates

End-to-End Testing and CI for Tauri

Test the real Tauri app with tauri-driver and WebdriverIO, understand platform limits, write stable selectors and waits, run tests in GitHub Actions, and try a runnable retry and page-object stand-in.

Unit tests with mocks prove that your pieces work separately. They cannot prove that the built app starts, that the frontend and the real Rust commands agree on argument names, or that a user can click through the main journey. End-to-end (E2E) tests start the actual application and drive it like a user. They are slower and more fragile, so you write only a few, for the flows that must never break.

This lesson shows how Tauri supports E2E testing through WebDriver, what its limits are, how to write reliable tests, and how to run everything in CI. Read Testing Tauri Apps: Rust Tests and Mocked IPC first.

Real versus stand-in. WebDriver tests need a built desktop app and display, so the bash, ts, toml and yaml blocks are real code to copy. The runnable blocks model the techniques that make E2E tests dependable: waiting with retries and page objects.

How Tauri E2E works

WebDriver is a standard protocol for controlling browsers. Tauri provides tauri-driver, a small program that speaks WebDriver on one side and starts your app on the other, using each platform's own webview driver:

flowchart LR
  T["Your test<br/>(WebdriverIO or Selenium)"] -->|WebDriver| D["tauri-driver"]
  D -->|Windows| E["msedgedriver"]
  D -->|Linux| W["WebKitWebDriver"]
  E --> A["Your Tauri app<br/>(real webview + real Rust)"]
  W --> A

The test controls the real window. Clicks reach your real frontend, and your frontend reaches your real Rust commands.

Limits to know:

  • Windows and Linux only. macOS has no WebDriver for WKWebView, so desktop E2E on a Mac is not supported by this route. Run E2E on Windows and Linux runners and rely on unit tests plus manual checks for macOS.
  • No mobile support through tauri-driver.
  • Tests control the webview, not native dialogs or menus: a native file dialog is outside the page. Design tests to avoid them, or mock the dialog result with a test-only command.

Setup

Install the driver and the platform's webview driver:

Terminal
cargo install tauri-driver --locked

# Linux
sudo apt-get install -y webkit2gtk-driver xvfb

# Windows: install msedgedriver matching your Edge version, e.g.
cargo install --git https://github.com/chippers/msedgedriver-tool

Create a test project, for example e2e/ with WebdriverIO:

Terminal
mkdir e2e && cd e2e
npm init -y
npm install --save-dev @wdio/cli
npx wdio config

A minimal wdio.conf.ts:

TypeScript
import { spawn, spawnSync, type ChildProcess } from 'node:child_process';
import os from 'node:os';
import path from 'node:path';

let tauriDriver: ChildProcess;
let exit = false;

const application = path.resolve(
  '../src-tauri/target/release/' + (os.platform() === 'win32' ? 'notes.exe' : 'notes'),
);

export const config = {
  host: '127.0.0.1',
  port: 4444,
  specs: ['./specs/**/*.ts'],
  maxInstances: 1,
  capabilities: [{ 'tauri:options': { application } }],
  reporters: ['spec'],
  framework: 'mocha',
  mochaOpts: { ui: 'bdd', timeout: 60000 },

  // build the app once before all tests
  onPrepare: () => {
    spawnSync('npm', ['run', 'tauri', 'build', '--', '--no-bundle'], {
      cwd: path.resolve('..'), stdio: 'inherit', shell: true,
    });
  },
  beforeSession: () => {
    tauriDriver = spawn(path.resolve(os.homedir(), '.cargo', 'bin', 'tauri-driver'), [], {
      stdio: [null, process.stdout, process.stderr],
    });
  },
  afterSession: () => {
    exit = true;
    tauriDriver.kill();
  },
};

A test uses ordinary WebdriverIO commands:

TypeScript
describe('notes app', () => {
  it('creates a note', async () => {
    await $('button[aria-label="New note"]').click();
    await $('input[name="title"]').setValue('Shopping');
    await $('button[type="submit"]').click();

    const item = await $('li=Shopping');
    await expect(item).toBeDisplayed();
  });
});

Use --no-bundle while testing to skip installers: you only need the binary.

Writing tests that do not flake

Most E2E pain comes from timing. The app responds asynchronously (Rust commands, animations, lazy loading), so a test that clicks and immediately asserts will sometimes fail. The fixes:

  1. Wait for conditions, never for time. Use waitForDisplayed, waitUntil or the auto-waiting in expect(...). Avoid browser.pause(2000).
  2. Use stable selectors. Prefer data-testid attributes, aria-labels and roles to CSS classes that change with styling.
  3. Start from a known state. Use a fresh data folder for each run (set an environment variable that points the app to a temp directory), so earlier tests do not affect later ones.
  4. Keep tests independent and short; each sets up its own data.
  5. Hide the selectors in page objects, so a markup change means one fix, not twenty.

The stand-in below shows a retrying waitUntil and a page object around a fake window.

Node.js Stand-in: waitUntil and a page object

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

Mocking what you cannot automate

Native dialogs, the clipboard and notifications live outside the webview. For tests, add a switch so the app takes the "choose file" result from a test fixture:

Rust
#[tauri::command]
fn pick_export_path(app: tauri::AppHandle) -> Option<String> {
    if let Ok(path) = std::env::var("NOTES_TEST_EXPORT_PATH") {
        return Some(path); // test mode: skip the dialog
    }
    // normal mode: show the dialog plugin here
    None
}

Keep such test hooks tiny and never reachable in a release build for users (guard them with cfg(debug_assertions) or a feature flag).

Running everything in CI

A GitHub Actions workflow that runs Rust tests, frontend tests and Linux E2E on every push:

YAML
name: test
on: [push, pull_request]

jobs:
  unit:
    runs-on: ubuntu-22.04
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with: { node-version: 22, cache: npm }
      - uses: dtolnay/rust-toolchain@stable
      - uses: Swatinem/rust-cache@v2
        with: { workspaces: src-tauri }
      - name: System libraries
        run: |
          sudo apt-get update
          sudo apt-get install -y libwebkit2gtk-4.1-dev libappindicator3-dev librsvg2-dev patchelf
      - run: npm ci
      - run: npm test
      - run: cargo test --manifest-path src-tauri/Cargo.toml
      - run: cargo clippy --manifest-path src-tauri/Cargo.toml -- -D warnings

  e2e:
    runs-on: ubuntu-22.04
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with: { node-version: 22, cache: npm }
      - uses: dtolnay/rust-toolchain@stable
      - uses: Swatinem/rust-cache@v2
        with: { workspaces: src-tauri }
      - run: |
          sudo apt-get update
          sudo apt-get install -y libwebkit2gtk-4.1-dev libappindicator3-dev librsvg2-dev patchelf webkit2gtk-driver xvfb
      - run: cargo install tauri-driver --locked
      - run: npm ci
      - run: npm ci
        working-directory: e2e
      - run: xvfb-run npm test
        working-directory: e2e

xvfb-run supplies a virtual display, because CI machines have no screen. Cache Rust builds (rust-cache), otherwise every run recompiles everything. Add cargo audit and npm audit as a separate job for the security checks from CSP, Isolation and Hardening. To publish builds, continue with Bundling and Installers.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which tool lets WebDriver clients control a Tauri app?

    tauri-driver starts your app and relays WebDriver commands to the platform's webview driver.
  2. 2. On which desktop systems does the standard WebDriver approach work?

    macOS has no WKWebView WebDriver, and mobile is not supported by tauri-driver.
  3. 3. Why prefer waitUntil over a fixed pause?

    Conditions adapt to timing, which is the main cure for flaky tests.
  4. 4. What does xvfb-run do in the CI workflow?

    Linux CI runners have no screen, so the app runs inside a virtual X server.

Summary

  • Tauri E2E tests use tauri-driver with WebdriverIO or Selenium on Windows and Linux; macOS and mobile are not covered.
  • Build the app, start the driver, and drive the real UI; native dialogs are outside reach, so use test hooks.
  • Avoid flakiness with condition waits, stable selectors, clean data and page objects.
  • CI runs cargo test, frontend tests, clippy and Linux E2E under xvfb-run, with Rust caching.

Next: The Updater and Releases