Tauri is a framework for building tiny, fast binaries for all major desktop and mobile platforms. Developers can integrate any frontend framework that compiles to HTML, JavaScript, and CSS for building their user experience while leveraging languages such as Rust, Swift, and Kotlin for backend logic when needed.
https://tauri.app/start

Testing Tauri apps with TestDriver

In this guide, we’ll leverage Playwright and the TestDriver Playwright SDK to convert the Tauri Quick Start to TestDriver’s selectorless, Vision AI.

Requirements

To start testing your Tauri app with TestDriver, you need the following:
1

Create a TestDriver Account

You will need a TestDriver Pro account ($20/month) to get an API key.

Sign Up for TestDriver

2

Set up your environment

Copy your API key from the TestDriver dashboard, and set it as an environment variable.
Export an environment variable on macOS or Linux systems:
export TD_API_KEY="your_api_key_here"
Follow Tauri’s Create a Project guide.
This is a condensed version of Playwright’s Installation Instructions.If you’re new to Playwright, you should follow their guide first.
In your Tauri project, run:
npm init playwright@latest
Select the following options when prompted:
✔ Do you want to use TypeScript or JavaScript?
> TypeScript
✔ Where to put your end-to-end tests?
> tests
✔ Add a GitHub Actions workflow? (y/N)
> N
✔ Install Playwright browsers (can be done manually via 'npx playwright install')? (Y/n)
> Y
@testdriver.ai/playwright is an AI-powered extension of @playwright/test.
npm install @testdriver.ai/playwright

Testing the Tauri Web App

Setup

First, we need to modify the default Playwright configuration and our Tauri project to work together:
1

Configure Playwright to start the Tauri frontend

In the playwright.config.ts file, we’ll configure the webServer to start the Tauri frontend for Playwright to test against:
playwright.config.ts
  /* Run your local dev server before starting the tests */
  webServer: {
    command: "npm run dev",
    url: "http://localhost:1420",
    reuseExistingServer: !process.env.CI,
    env: {
      VITE_PLAYWRIGHT: "true",
    },
  },
});
2

Mock Tauri APIs

Since we’re testing the Tauri frontend, we need to mock IPC Requests to simulate invoke calls to the Rust backend:
src/index.html
<body>
  <div id="root"></div>
  <script type="module">
    // This is set in playwright.config.ts to allow our tests to mock Tauri IPC `invoke` calls
    if (import.meta.env.VITE_PLAYWRIGHT) {
      const { mockIPC } = await import("@tauri-apps/api/mocks");
      window.mockIPC = mockIPC;
    }
  </script>
  <script type="module" src="/src/main.tsx"></script>
</body>
We only need to do this once, as we’ll be accessing window.mockIPC in our tests.
3

Create a new test file

Create a new file (e.g. tests/testdriver.spec.ts) with:
tests/testdriver.spec.ts
import type { mockIPC } from "@tauri-apps/api/mocks";
import { expect, test } from "@playwright/test";

test.beforeEach(async ({ page }) => {
  await page.goto("http://localhost:1420");
});

test("should have title", async ({ page }) => {
  await expect(page).toHaveTitle("Tauri + React + TypeScript");
});
4

Run Playwright in UI Mode

Now we’re ready to run Playwright and start working on our tests:
npx playwright test --ui
Playwright UI ModeClick the button to successfully run the tests in the UI.
Click the button to automatically re-run tests on save.

Usage

Import the TestDriver Playwright SDK

By changing 1 line, we can add TestDriver’s AI capabilities to Playwright:
tests/testdriver.spec.ts
import type { mockIPC } from "@tauri-apps/api/mocks";
import { expect, test } from "@playwright/test";
import { expect, test } from "@testdriver.ai/playwright";

// For type-safety of the mockIPC function
declare global {
  interface Window {
    mockIPC: typeof mockIPC;
  }
}

test.beforeEach(async ({ page }) => {
  await page.goto("http://localhost:1420");
});

test("should have title", async ({ page }) => {
  await expect(page).toHaveTitle("Tauri + React + TypeScript");
});
Notice how we’re able to continue using Playwright’s API (toHaveTitle) with @testdriver.ai/playwright. The test continues to pass as before, so now we can update our test to use natural language instead of selectors.

Assertions with expect.toMatchPrompt

With Playwright, we would normally use a getByRole selector to assert the heading text:
tests/example.spec.ts
test("should have heading", async ({ page }) => {
  await expect(
    page.getByRole("heading", { name: "Installation" }),
  ).toBeVisible();
});
With TestDriver, we can use natural language with toMatchPrompt instead:
tests/testdriver.spec.ts
test("should have heading", async ({ page }) => {
  await expect(
    page.getByRole("heading", { name: "Installation" }),
  ).toBeVisible();
  await expect(page).toMatchPrompt("Heading says 'Welcome to Tauri + React'");
});

Agentic tests with test.agent

With TestDriver, we can skip the test implementation entirely and let AI perform the test for us:
1

Mock the `greet` call

First, we need to mock our invoke calls, since we’re testing the frontend behavior and not our Tauri backend:
tests/testdriver.spec.ts
test.beforeEach(async ({ page }) => {
  await page.goto("http://localhost:1420");
  await page.evaluate(() => {
    // https://tauri.app/develop/tests/mocking/#mocking-commands-for-invoke
    window.mockIPC((cmd, args) => {
      switch (cmd) {
        case "greet":
          args = args as { name: string };
          return `Hello, ${args.name}! You've been greeted from Rust!`;
        default:
          throw new Error(`Unsupported command: ${cmd}`);
      }
    });
  });
});
2

Add an Agentic Test

Next, wrap a prompt in test.agent to perform the test:
tests/testdriver.spec.ts
test.describe("should greet with name", () => {
  test.agent(`
    - Enter the name "Tauri"
    - Click the "Greet" button
    - You should see the text "Hello, Tauri! You've been greeted from Rust!"
  `);
});

Continued Reading

Learn more about TestDriver’s Playwright SDK

Testing the Tauri Desktop App

We can use TestDriver and natural language to test our Tauri desktop app:
1

Run the Desktop App

npm run tauri dev
2

Continued Reading

See Desktop Apps for more information.

Testing the Tauri Mobile App

We can use TestDriver and natural language to test our Tauri iOS app:
1

Run the Mobile App

npm run tauri ios dev
2

Continued Reading

See Mobile Apps for more information.