使用 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 访问相关的内容,但没有找到任何有效/正确的文档。

如果有人已经研究过这个主题,请你帮我解决这个问题。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)