@crabnebula/tauri-driver

中文文档
2.0.9发布于 2026/02/12MITTypeScriptCommonJS零依赖近 30 天下载 4.2万

End-to-end testing for Tauri apps via Webdriver.

原始使用文档
文档目录4 节
  1. Prerequisites
  2. Installation
  3. Usage
  4. WebdriverIO

CrabNebula Tauri Driver

End-to-end testing for Tauri apps via Webdriver.

@crabnebula/tauri-driver acts as a bridge between the Webdriver client defining the integration tests and the target platform's Webdriver implementation.

Currently supported platforms:

  • macOS via CrabNebula Webdriver for Tauri
  • Linux via webkit2gtk-driver or the CrabNebula Webdriver
  • Windows via msedgedriver or the CrabNebula Webdriver

Prerequisites

  • macOS: Your Tauri app must have the tauri-plugin-automation plugin installed in order to run integration tests on macOS
  • Linux: webkit2gtk-driver must be installed in your system and available in the PATH
  • Windows: msedgedriver.exe must be installed in your system and available in the PATH

Alternatively for Linux and Windows you can also use tauri-plugin-automation and configure your test to execute the test runner backend.

Installation

Install with your favorite package manager:

npm install --save-dev @crabnebula/tauri-driver
yarn install -D @crabnebula/tauri-driver
pnpm install -D @crabnebula/tauri-driver

Additionally you should install @crabnebula/test-runner-backend if you wish to run macOS tests locally, and @crabnebula/webdriverio-cloud-reporter to upload test results to CrabNebula Cloud.

Usage

WebdriverIO

Let's define a WebdriverIO configuration that starts tauri-driver so it can run your integration tests.

  1. Import packages
import path from"path";
import { spawn, spawnSync } from "child_process";
import { CrabNebulaCloudReporter } from "@crabnebula/webdriverio-cloud-reporter";
import { waitTauriDriverReady } from "@crabnebula/tauri-driver";
import { waitTestRunnerBackendReady } from "@crabnebula/test-runner-backend";
  1. Set your application path

For macOS you can optionally use the .app bundle instead of just your app executable.

const applicationPath = process.platform === "darwin"
  ? "path/to/src-tauri/target/debug/bundle/macos/<app-name>.app"
  : process.platform === "win32"
  ? "path/to/src-tauri/target/debug/<app-name>.exe"
  : "path/to/src-tauri/target/debug/<app-name>"

Note that you must use the proper target folder path relative to your WebdriverIO configuration file and replace <app-name> with the correct values.

  1. Create global variables
// keep track of the `tauri-driver` child process
let tauriDriver;
let killedTauriDriver = false;
// keep track of the `test-runner-backend` child process
let testRunnerBackend;
let killedTestRunnerBackend = false;
  1. Define the WebdriverIO configuration

Note that this example assumes you are using pnpm, please adjust the scripts if you are using a different package manager.

exports.config = {
  host: "127.0.0.1",
  port: 4444,
  specs: ["./test/specs/**/*.js"],
  maxInstances: 1,

  capabilities: [
    {
      maxInstances: 1,
      "tauri:options": {
        application: applicationPath,
      },
    },
  ],
  reporters: [CrabNebulaCloudReporter],
  framework: "mocha",
  mochaOpts: {
    ui: "bdd",
    timeout: 60000,
  },
  connectionRetryCount: 0,

  onPrepare: async () => {
    // ensure the Tauri app is built since we expect this binary to exist for the webdriver sessions
    spawnSync("pnpm", ["tauri", "build", "--debug"], {
      cwd: path.resolve(__dirname, "path/to/src-tauri"), // TODO: use actual path to the Tauri app directory
      stdio: "inherit",
      shell: true,
    });

    // skip this if condition to use the CrabNebula Webdriver on all platforms
    if (process.platform === "darwin") {
      // CN_API_KEY is required to run macOS tests via CrabNebula Webdriver for Tauri
      if (!process.env.CN_API_KEY) {
        console.error(
          "CN_API_KEY is not set, required for CrabNebula Webdriver"
        );
        process.exit(1);
      }

      testRunnerBackend = spawn("pnpm", ["test-runner-backend"], {
        stdio: "inherit",
        shell: true,
      });

      testRunnerBackend.on("error", (error) => {
        console.error("test-runner-backend error:", error);
        process.exit(1);
      });
      testRunnerBackend.on("exit", (code) => {
        if (!killedTestRunnerBackend) {
          console.error("test-runner-backend exited with code:", code);
          process.exit(1);
        }
      });

      await waitTestRunnerBackendReady();

      // instruct tauri-driver to connect to the test-runner-backend
      process.env.REMOTE_WEBDRIVER_URL = `http://127.0.0.1:3000`;
    }
  },

  // ensure we are running `tauri-driver` before the session starts so that we can proxy the webdriver requests
  beforeSession: async () => {
    tauriDriver = spawn("pnpm", ["tauri-driver"], {
      stdio: [null, process.stdout, process.stderr],
      shell: true,
    });
    tauriDriver.on("error", (error) => {
      console.error("tauri-driver error:", error);
      process.exit(1);
    });
    tauriDriver.on("exit", (code) => {
      if (!killedTauriDriver) {
        console.error("tauri-driver exited with code:", code);
        process.exit(1);
      }
    });

    // wait for tauri-driver to initialize its proxy server
    await waitTauriDriverReady();
  },

  // clean up the `tauri-driver` process we spawned at the start of the session
  afterSession: () => {
    closeTauriDriver();
  },

  onComplete: () => {
    killedTestRunnerBackend = true;
    testRunnerBackend?.kill();
  },
};

function closeTauriDriver() {
  killedTauriDriver = true;
  tauriDriver?.kill();
  killedTestRunnerBackend = true;
  testRunnerBackend?.kill();
}

export function onShutdown(fn) {
  const cleanup = () => {
    try {
      fn();
    } finally {
      process.exit();
    }
  };

  process.on("exit", cleanup);
  process.on("SIGINT", cleanup);
  process.on("SIGTERM", cleanup);
  process.on("SIGHUP", cleanup);
  process.on("SIGBREAK", cleanup);
}

onShutdown(closeTauriDriver);

版本与发布记录

@crabnebula/tauri-driver 共发布 10 个版本,首次发布于 2025/06/05;过去 12 个月发布了 1 个版本。

版本发布日期距今
2.0.9latest2026/02/128 个月前
2.0.82025/08/161.2 年前
2.0.72025/08/151.2 年前
2.0.62025/08/141.2 年前
2.0.52025/08/031.3 年前
2.0.42025/07/311.3 年前

关于 @crabnebula/tauri-driver 的常见问题

@crabnebula/tauri-driver 是什么?

End-to-end testing for Tauri apps via Webdriver.

如何安装 @crabnebula/tauri-driver?

在项目目录运行 npm install @crabnebula/tauri-driver,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 tauri-driver,可以用 npx tauri-driver 直接运行。

@crabnebula/tauri-driver 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@crabnebula/tauri-driver 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@crabnebula/tauri-driver 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >= 10。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@crabnebula/tauri-driver 可以商用吗?

@crabnebula/tauri-driver 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@crabnebula/tauri-driver 的下载量有多少?

根据 npm 官方下载统计,@crabnebula/tauri-driver 在 2026/10/11 – 2026/11/09 这 30 天内被下载 42,270 次,日均约 1,409 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@crabnebula/tauri-driver 还在维护吗?

最新版本 2.0.9 发布于 2026/02/12(8 个月前);至今共发布 10 个版本,其中过去 12 个月发布了 1 个;首次发布于 2025/06/05。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。