Web UI 测试自动化
最后修改时间:2023 年 12 月 4 日PyCharm 中的 Web UI 测试自动化功能由测试自动化插件提供。该插件有助于开发和维护自动化 UI 测试,并包含Aqua(用于测试自动化的独立 JetBrains IDE)提供的大部分功能。
测试自动化插件提供以下功能:
笔记
从 PyCharm 2023.3 开始,Selenium、Cypress 和 Playwright 测试都可以被识别,并且可以立即运行或调试,无论是否安装了测试自动化插件。但是,其他功能的可用性需要安装该插件。
有关测试自动化功能的更多信息,请参阅Aqua 官方文档。
安装测试自动化插件
在“设置”对话框 ( ) 中,选择“插件”。CtrlAlt0S
切换到Marketplace选项卡,输入
Test Automation
,然后单击Install。单击“应用”保存更改并关闭对话框。如果出现提示,请重新启动 IDE。
测试自动化功能
测试识别能力
当您打开项目时,PyCharm 会自动检测Selenium / Cypress / Playwright测试。可以通过单击装订线中的图标来运行已识别的测试。



编码协助
提供的编码辅助功能包括智能代码补全、导航、语法突出显示、linter 支持、对特定于框架的函数和表达式的支持等等。
例如,您可以开始在代码编辑器中键入定位器或其子字符串,自动完成功能将为您提供可供选择的元素列表。



定位器生成和验证
Web Inspector工具窗口允许您查看 Web 应用程序并捕获自动化测试所需的页面元素。当您在网页上选择所需的元素时,PyCharm 会生成唯一的 CSS 或 XPath 定位器,并帮助将其添加到源代码中。此外,PyCharm 可以生成Playwright 中使用的基于角色的定位器。这些定位器旨在反映元素的角色(例如按钮或复选框),使其更容易识别。

此外,Web Inspector可以帮助您验证代码中的定位器是否有效并指向网页上的正确元素。单击代码编辑器中定位器旁边的图标将打开Web 检查器并选择相应的元素,从而验证定位器是否存在。

有关Web Inspector 的更多信息,请参阅Aqua 文档。
管理测试的运行/调试配置
运行/调试配置是一组启动属性,定义要执行的内容以及执行期间应使用哪些参数和环境。
您可以为您的测试创建不同的配置集,并根据您的需要在它们之间立即切换。



测试执行细节
测试运行完成后,您将获得全面的测试结果,包括每个测试的相关日志和控制台输出。您可以过滤结果以快速浏览失败或忽略的测试并分析其执行时间。



调试器
用于Selenium和Playwright测试的调试器是开箱即用的。您可以设置断点来停止执行并分析代码。


感谢您的反馈意见!