【问题标题】:Open universal links (deep links) with XCUITest使用 XCUITest 打开通用链接(深层链接)
【发布时间】:2018-09-04 07:16:44
【问题描述】:

我想为原生 iOS 应用程序创建几个测试。更准确地说,我想测试深层链接。但我不确定如何触发与 XCUITest 的深层链接,而且我真的不知道 launch() 和 launcArguments (https://developer.apple.com/documentation/xctest/xcuiapplication) 可以如何帮助我。有人有机会打开 XCUITest 的深层链接吗?

【问题讨论】:

  • 深层链接是什么意思?请提供信息。
  • @ablarg 我的意思是说“通用链接”(developer.apple.com/videos/play/wwdc2015/509)。对不起,我用了“深”这个词,因为这是它在 android 世界中的命名方式:)

标签: xcuitest


【解决方案1】:
  1. 将 safari 设置为这样的应用

    let safari = XCUIApplication(bundleIdentifier: "com.apple.mobilesafari")

  2. 在 Safari 中打开您的电子邮件

  3. 点击链接
  4. 通常在应用上声明某些元素

【讨论】:

  • 感谢您的建议。那正是我结束的地方。不幸的是,目前在 XCUITest 中似乎没有其他方法:(
【解决方案2】:

我从未尝试过,但我想到了这个想法。创建一个新的虚拟项目/应用程序,它应该只包含一些指向您希望原始应用程序打开的 URL 的链接。在这个新应用程序中,编写一些点击链接的 UI 测试,如下所示:

func testOpeningLinks() {
    let app = XCUIApplication()
    app.links["Some link text"].tap()
    // This is the place where your original app should be opened...

    // Find the XCUIApplication object:
    let originalApp = XCUIApplication(bundleIdentifier: "original.app.bundle.identifier")
    // You should be able to find some views from original app from here, eg. a button:
    let button = originalApp.buttons.element
}

仅当您之前在运行 UI 测试的设备/模拟器上安装了应用程序时,这才有效。

【讨论】:

    【解决方案3】:

    在 iOS 14 中使用 Spotlight 似乎效果很好:

        private func open(_ urlString: String) {
            XCUIDevice.shared.press(.home)
            XCUIApplication(bundleIdentifier: "com.apple.springboard").swipeDown()
            let spotlight = XCUIApplication(bundleIdentifier: "com.apple.Spotlight")
            spotlight.textFields["SpotlightSearchField"].typeText(urlString)
            spotlight.buttons["go"].tap()
        }
    

    【讨论】:

    • “Go”应该大写吗?
    猜你喜欢
    • 1970-01-01
    • 2021-12-20
    • 1970-01-01
    • 1970-01-01
    • 2016-06-26
    • 2016-10-21
    • 1970-01-01
    • 2023-03-27
    • 1970-01-01
    相关资源
    最近更新 更多