ios - 使用 XCTestCases 类中的可访问性标识符访问 NavigationLink - SwiftUI
问题描述
我最近开始研究 SwiftUI 框架,我正在使用 XCTest 编写 UI 测试用例。
NavigationLink("Login", destination: TabBarDashboardView())
.accessibility(identifier: "linkLogin")
.frame(width: 200, height: 50, alignment: .center)
.foregroundColor(.white)
.background(Color.red)
.padding([.top, .bottom], 40)
在 XCTestCase 类中,我尝试了以下代码来点击 NavigationLink:
func testLoginActionAndNavigation() throws {
let linkLogin = self.app.navigationBars.links["linkLogin"]
linkLogin.tap()
XCTAssertEqual(linkLogin.title, "linkLogin")
}
我收到以下错误,并且测试用例失败:
Failed to get matching snapshot: No matches found for Descendants matching type Link from input {( NavigationBar, identifier: '_TtGC7SwiftUI19UIHosting' )}
我在 XCTestCase 类中搜索与 NavigationLink 访问相关的内容,但没有找到任何有效/正确的文档。
如果有人已经在这个主题上工作过,请你帮我解决这个问题。
解决方案
推荐阅读
- dart - Dart/Flutter 中的单元测试异常
- python - 我可以在哪里使用 grid() 方法在 Tkinter 上存储图像?
- selenium - 如何在任何远程机器上启动 chrome 驱动程序
- angular - Angular 9 和 dotnet WebAPI 路由
- asp.net - Sitefinity 自定义小部件 - 部署外部程序集
- java - Java:JSONObject isNull 方法无法正常工作
- c - 如何将字符串添加到二进制文件的开头
- python-3.x - 从列到总计所有值并创建一个新行名称“TOTAL”
- javascript - 其他选项卡中的异步操作
- c - C - 将结构逐字节写入 NVM