# Web UI 测试自动化

> For the complete documentation index, see [llms.txt](https://www.jetbrains.com.cn/help/idea/llms.txt).

IntelliJ IDEA 中的 Web UI 测试自动化功能由 [Test Automation](https://plugins.jetbrains.com/plugin/20175-test-automation) 插件提供。 此插件有助于开发和维护自动化 UI 测试，并且构成了 [Aqua](https://www.jetbrains.com.cn/aqua/)（用于测试自动化的独立 JetBrains IDE）所提供功能的重要部分。

Test Automation  插件提供以下功能：

* 对 [Selenium](selenium.html)、 [Cypress](cypress.html) 和 [Playwright](playwright.html) 框架的丰富支持

* 能够 [运行](#run-tests)、 [调试](#debug-tests)和 [检查](#review-test-results) Selenium/Cypress/Playwright 测试

* 广泛的 [编码辅助](#editing-code)

* [定位器生成和验证](#generate-locators)

> **Note:**
> 从 IntelliJ IDEA 2023.3 开始，Selenium、Cypress 和 Playwright 测试被识别并且可以立即运行或调试，无论是否安装  Test Automation  插件。

如需了解有关测试自动化功能的更多信息，请参阅 [官方 Aqua 文档](https://www.jetbrains.com.cn/help/aqua)。

Procedure: 安装 Test Automation 插件

1. 在   设置  对话框（ `Ctrl+Alt+S` (Windows), `⌘ Comma` (macOS), `⌘ Comma` (IntelliJ IDEA Classic (macOS)), `⌘ Comma` (macOS System Shortcuts), `Ctrl+Alt+S` (XWin), `Ctrl+Alt+S` (GNOME), `Ctrl+Alt+S` (KDE), `Ctrl+Alt+S` (Emacs), `Ctrl+Alt+S` (Sublime Text), `⌘ Comma` (Sublime Text (macOS)), `Ctrl+Alt+S` (Visual Studio), `⌘ Comma` (Visual Studio (macOS)), `Ctrl+Alt+S` (NetBeans), `Ctrl+Alt+S` (Eclipse), `⌘ Comma` (Eclipse (macOS))）中，选择   插件  。

2. 找到   测试自动化   插件并点击   安装  。

3. 点击   应用  保存更改并关闭对话框。 如果出现提示，请重启 IDE。

## 测试自动化功能

### 测试识别

当您打开项目时，IntelliJ IDEA 会自动检测用 Selenium、Cypress 或 Playwright 编写的测试。 识别出的测试可以通过点击装订区域中的 ![运行图标](https://resources.jetbrains.com.cn/help/img/idea/2026.3/app-client.expui.run.run.svg) 图标来运行，然后使用 IDE 的工具进行 [分析](#review-test-results)/ [调试](#debug-tests)。

Selenium:

![查看测试](https://resources.jetbrains.com.cn/help/img/idea/2026.3/aqua_selenium_run_tests.png)

Cypress:

![查看测试](https://resources.jetbrains.com.cn/help/img/idea/2026.3/aqua_cypress_run_tests.png)

Playwright:

![查看测试](https://resources.jetbrains.com.cn/help/img/idea/2026.3/aqua_pw_run_tests.png)

### 编码辅助

提供的编码辅助功能包括智能代码补全、 [导航](navigating-through-the-source-code.html)、 [语法高亮显示](configuring-colors-and-fonts.html)、对框架特定函数／方法和表达式的支持等。

例如，您可以在代码编辑器中开始输入定位器或其子字符串，自动完成功能将为您提供一个可选元素列表。 此外，所选元素将在   Web 检查器   中高亮显示，从而更容易选择正确的定位器。

[Video](https://resources.jetbrains.com.cn/help/img/idea/2026.3/aqua_locator_code_completion.mp4)

### 定位器生成与验证

Web 检查器   工具窗口可用于查看 web 应用程序并捕获自动化测试所需的页面元素。 在 web 页面上选择所需元素时，IntelliJ IDEA 会生成一个唯一的 CSS 或 XPath 定位器，并帮助将其添加到源代码中。

[Video](https://resources.jetbrains.com.cn/help/img/idea/2026.3/aqua_locators_evaluator.mp4)

此外，IntelliJ IDEA 可以生成用于 Playwright 的 [基于角色的](playwright.html#role_based_locators_support)定位器。 这些定位器旨在反映元素的角色（例如，按钮或复选框），从而更容易识别。

![基于角色的定位器](https://resources.jetbrains.com.cn/help/img/idea/2026.3/aqua_playwright_role_based_locators.png)

此外，   Web 检查器   可帮助验证代码中的定位器是否有效，并且是否指向 web 页面上的正确元素。 点击代码编辑器中定位器旁边的 ![](https://resources.jetbrains.com.cn/help/img/idea/2026.3/aqua-plugin.icons.inlayWebInspector.svg) 图标会打开   Web 检查器   并选择相应元素，从而验证该定位器。

[Video](https://resources.jetbrains.com.cn/help/img/idea/2026.3/aqua_validating_locators.mp4)

> **Tip:**
> 有关   Web 检查器  的更多信息，请参阅 [Aqua 文档](https://www.jetbrains.com.cn/help/aqua/web-inspector-overview.html)。

### 管理测试的运行 / 调试配置

运行/调试配置是一组启动属性，定义了要执行的内容以及在执行过程中应使用的参数和环境。

您可以为测试创建不同的 [配置](run-debug-configuration.html)集，并根据需要即时切换。

Selenium:

![管理测试运行配置](https://resources.jetbrains.com.cn/help/img/idea/2026.3/aqua_selenium_run_debug_config.png)

Cypress:

![管理测试运行配置](https://resources.jetbrains.com.cn/help/img/idea/2026.3/aqua_cypress_run_debug_config.png)

Playwright:

![管理测试运行配置](https://resources.jetbrains.com.cn/help/img/idea/2026.3/aqua_pw_run_debug_config.png)

### 测试执行详情

测试运行完成后，将提供全面的结果，包括每个测试的日志和控制台输出，以便轻松 [浏览](viewing-and-exploring-test-results.html)。 您可以过滤结果，以便快速浏览失败或被忽略的测试，并分析它们的执行时间。

Selenium:

![查看测试结果](https://resources.jetbrains.com.cn/help/img/idea/2026.3/aqua_selenium_failed_tests.png)

Cypress:

![查看测试结果](https://resources.jetbrains.com.cn/help/img/idea/2026.3/aqua_cypress_failed_tests.png)

Playwright:

![查看测试结果](https://resources.jetbrains.com.cn/help/img/idea/2026.3/aqua_pw_failed_tests.png)

### 调试器

[调试器](debugging-code.html)是一种用于测试和排查代码问题的工具。 它允许您逐步运行代码，并为您提供每一步发生的详细信息。

开箱即用的 Selenium 和 Playwright 测试调试器。 您可以设置 [断点](using-breakpoints.html)以暂停执行并分析代码。

> **Note:**
> 由于框架特性的限制，经典的  "IDE 内" 调试方法并不真正适用于 Cypress。 但是，如果您有适合经典方法的用例，请随时使用 [此](https://youtrack.jetbrains.com/newIssue?project=AQUA&summary=%5BIn-IDE+Cypress+Debugging%5D+%3CSpecify+a+title+here%3E&description=**Description%3A**%0A%3CProvide+a+description+of+your+use+case+and+share+your+thoughts+on+why+you+think+a+classic+%22in-IDE%22+debugging+approach+makes+sense+in+your+particular+case.%3E%0A%0A**Additional+information**%0A%3CFeel+free+to+include+any+relevant+details+such+as+the+context%2C+steps+to+reproduce%2C+screenshots%2C+etc.%3E%0A%0A**IDE**%0A%3CWhat+IDE+do+you+use%3F%3E&c=add+Board+Aqua%3A+PM+%26+Strategy&c=add+Board+Aqua%3A+Content+%26+Marketing&c=Type+Usability+Problem&c=Subsystem+Frameworks&c=Framework+Cypress)表单与我们分享。

Selenium:

![调试器](https://resources.jetbrains.com.cn/help/img/idea/2026.3/aqua_selenium_debugger.png)

Playwright:

![调试器](https://resources.jetbrains.com.cn/help/img/idea/2026.3/调试配置](run-debug-configuration.html)

### 外部链接

[Selenium](https://www.selenium.dev/) [Cypress](https://www.cypress.io/) [Playwright](https://playwright.dev/)

