Skip to content
Tauri 中文网

WebDriver

WebDriver 是一个用于与网页文档交互的标准化接口,主要用于自动化测试。Tauri 通过在一个跨平台封装器 tauri-driver 下面利用原生平台的 WebDriver 服务器来支持 WebDriver 接口。在桌面端,由于 macOS 没有可用的 WKWebView 驱动工具,因此仅支持 Windows 和 Linux。iOS 和 Android 通过 Appium 2 工作,但该过程目前尚未优化。

🌐 System Dependencies

通过运行以下命令安装最新的 tauri-driver 或更新现有安装:

🌐 Install the latest tauri-driver or update an existing installation by running:

Terminal window
cargo install tauri-driver --locked

因为我们目前使用平台本地的 WebDriver 服务器,所以在支持的平台上运行 tauri-driver 有一些要求。

🌐 Because we currently utilize the platform’s native WebDriver server, there are some requirements for running tauri-driver on supported platforms.

我们在 Linux 平台上使用 WebKitWebDriver。通过运行 which WebKitWebDriver 命令检查此二进制文件是否已经存在,因为某些发行版将其与常规的 WebKit 包打包在一起。其他平台可能有单独的包,例如基于 Debian 的发行版上的 webkit2gtk-driver

🌐 We use WebKitWebDriver on Linux platforms. Check if this binary exists already by running the which WebKitWebDriver command as some distributions bundle it with the regular WebKit package. Other platforms may have a separate package for them, such as webkit2gtk-driver on Debian-based distributions.

请确保下载与应用构建和测试所使用的 Windows Edge 版本匹配的 [Microsoft Edge 驱动程序] 版本。这几乎总是应该是最新稳定版本,适用于最新的 Windows 安装。如果两个版本不匹配,你可能会在 WebDriver 测试套件尝试连接时遇到挂起的问题。

🌐 Make sure to grab the version of Microsoft Edge Driver that matches your Windows Edge version that the application is being built and tested on. This should almost always be the latest stable version on up-to-date Windows installs. If the two versions do not match, you may experience your WebDriver testing suite hanging while trying to connect.

你可以使用 msedgedriver-tool 下载合适的 Microsoft Edge 驱动程序:

🌐 You can use the msedgedriver-tool to download the appropriate Microsoft Edge Driver:

Terminal window
cargo install --git https://github.com/chippers/msedgedriver-tool
& "$HOME/.cargo/bin/msedgedriver-tool.exe"

下载内容包含一个名为 msedgedriver.exe 的二进制文件。tauri-driver 会在 $PATH 中查找该二进制文件,因此请确保它在路径中可用,或者在 tauri-driver 上使用 --native-driver 选项。你可能希望在 CI 设置过程中自动下载它,以确保 Windows CI 计算机上的 Edge 和 Edge Driver 版本保持同步。关于如何执行此操作的指南可能会在以后添加。

🌐 The download contains a binary called msedgedriver.exe. tauri-driver looks for that binary in the $PATH so make sure it’s either available on the path or use the --native-driver option on tauri-driver. You may want to download this automatically as part of the CI setup process to ensure the Edge, and Edge Driver versions stay in sync on Windows CI machines. A guide on how to do this may be added at a later date.

🌐 Example Applications

下面是分步指南,展示如何创建一个经过 WebDriver 测试的最小示例应用。

🌐 Below are step-by-step guides to show how to create a minimal example application that is tested with WebDriver.

如果你想查看指南的结果并查看使用它的完成的最小代码库,你可以访问 https://github.com/tauri-apps/webdriver-example。

🌐 If you prefer to see the result of the guide and look over a finished minimal codebase that utilizes it, you can look at https://github.com/tauri-apps/webdriver-example.

🌐 Continuous Integration (CI)

上面的示例还附带了一个 CI 脚本,可以使用 GitHub Actions 进行测试,但你可能仍然对下面的 WebDriver CI 指南感兴趣,因为它更详细地解释了这个概念。

🌐 The above examples also comes with a CI script to test with GitHub Actions, but you may still be interested in the below WebDriver CI guide as it explains the concept a bit more.


Tauri 中文网 - 粤ICP备13048890号
Nodejs.cn 旗下网站