关于 xcuitest
面向 Swift 6 的 XCUITest UI 测试参考技能,将 API 指引、示例和故障排查整理为可搜索的本地文件。
主要功能
- 01元素查询与交互
- 02等待与断言
- 03Swift 6 并发指引
- 04截图与启动设置
- 05权限与测试辅助工具
- 06故障排查与测试模式
适用场景
- 01编写 XCUITest 测试用例
- 02处理异步 UI 元素
- 03测试权限与系统提醒
- 04排查不稳定的 UI 测试
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ prisma-labs-dev/ apple-skills --skill xcuitest安装后在 Claude Code 中输入/xcuitest确认已加载。
包含的文件
除 SKILL.md 外,安装时一起下载的参考资料和脚本。
assertions.mdelement-queries.mdinteractions.mdlaunch-arguments.mdpatterns.mdpermissions.mdscreenshots.mdswift6-concurrency.mdtest-helpers.mdtroubleshooting.mdwaiting.mdxctest-index.mdxcuiapplication.mdxcuiautomation-index.mdxcuicoordinate.mdxcuielement.mdxcuielementquery.mdxcuiprotectedresource.mdxcuiscreenshot.md详细介绍
XCUITest 参考
使用 Swift 6 编写可靠 XCUITest UI 测试的全面参考。
快速参考
// Basic test structure
@MainActor
final class MyUITests: XCTestCase {
var app: XCUIApplication!
override func setUp() {
super.setUp()
continueAfterFailure = false
app = XCUIApplication()
app.launch()
}
func testExample() {
let button = app.buttons["Submit"]
XCTAssertTrue(button.waitForExistence(timeout: 5))
button.tap()
}
}
主题指南
精选指南及代码示例(便于使用 grep 搜索):
| 文件 | 内容 |
|---|---|
| element-queries.md | 核心 API 类:XCUIApplication、XCUIElement、XCUIElementQuery、XCUICoordinate |
| interactions.md | 点击、按压、文本输入、滑动、基于坐标的手势及其他手势 |
| waiting.md | waitForExistence、XCTWaiter、不存在状态、属性等待、Xcode 26 KeyPath 等待 |
| swift6-concurrency.md | Swift 6 严格并发:@MainActor 测试类、异步 setUp/tearDown、nonisolated |
| assertions.md | XCTAssert 模式、自定义消息、存在性检查 |
| screenshots.md | 截图、XCTAttachment、失败时截图、从 .xcresult 中提取 |
| launch-arguments.md | 启动参数/环境、UserDefaults 覆盖、本地化和辅助功能测试 |
| permissions.md | resetAuthorizationStatus、XCUIProtectedResource、中断监视器、springboard/系统警告框 |
| test-helpers.md | 页面对象模型、可复用辅助工具、超时常量 |
| troubleshooting.md | 常见故障(找不到元素、测试不稳定)以及 Xcode 26 / iOS 26 新内容 |
| patterns.md | 高级模式:基础测试类、系统对话框、滚动/等待、调试、测试组织 |
已下载的参考文件
本地提供的 Apple 文档页面:
| 文件 | 内容 |
|---|---|
| xctest-index.md | XCTest 框架完整索引 |
| xcuiautomation-index.md | XCUIAutomation 框架完整索引 |
| xcuiapplication.md | XCUIApplication 类 |
| xcuielement.md | XCUIElement 类 |
| xcuielementquery.md | XCUIElementQuery 类 |
| xcuicoordinate.md | XCUICoordinate 类 |
| xcuiprotectedresource.md | XCUIProtectedResource 枚举 |
| xcuiscreenshot.md | XCUIScreenshot 类 |
来源
Apple 文档
- XCTest | Apple Developer Documentation
- XCUIAutomation | Apple Developer Documentation
- XCUIElementQuery | Apple Developer Documentation
- waitForExistence | Apple Developer Documentation
- wait(for:toEqual:timeout:) | Apple Developer Documentation
- resetAuthorizationStatus(for:) | Apple Developer Documentation
- XCUIProtectedResource | Apple Developer Documentation
- XCUIScreenshot | Apple Developer Documentation
WWDC 专题
社区资源
- XCTest Meets @MainActor | Quality Coding
- Issues with setUp() and tearDown() in XCTest for Swift 6 | Swift Forums
- Waiting in XCTest | Masilotti.com
- UI Testing Cheat Sheet | Masilotti.com
- XCUIElement Actions and Gestures | Apps Developer Blog
- Configuring UI tests with launch arguments | polpiella.dev
- UI Testing improvements in Xcode 16 | Jesse Squires
获取更多 Apple 文档
- 先搜索此技能本地的
.md文件。 - 如果其中没有相关主题,请根据名称、描述或
SKILL.mdfrontmatter,查看你可用的其他已安装 Apple 技能,然后 grep 其本地文件。这样比从互联网获取新文档更快,且占用的上下文更少。 - 如果没有已安装的技能包含该页面,请使用本地 XCTest 或 XCUIAutomation 索引中的相关文档路径,通过
sosumi.aiMarkdown 镜像获取。例如,/documentation/xcuiautomation/xcuielement对应https://sosumi.ai/documentation/xcuiautomation/xcuielement。
评论
支持 Markdown