【问题标题】:springboard.icons["appName"] does not recognize the installed app in XCUITestspringboard.icons["appName"] 无法识别 XCUITest 中已安装的应用程序
【发布时间】:2019-12-12 14:55:10
【问题描述】:

我指的是在运行每个 XCUItest 后删除应用程序的下面的 github 代码。 https://gist.github.com/KoCMoHaBTa/5d2cecfc17db5f3944bc98bcd6fcde55

但是代码 sn-p let icon = springboard.icons["myAppName"] 无法识别我的应用。我已将 myAppName 替换为我的应用程序名称以及检查 icon.exists 是否始终返回 false 的 if 条件。跳板类如下所示。我这里有什么遗漏吗?

class Springboard {

    static let shared = Springboard()

    let springboard = XCUIApplication(bundleIdentifier: "com.company.me")

    func deleteApp(withName name: String) {

        XCUIApplication().terminate()

        let springboard = self.springboard
        //springboard.resolve()
        springboard.activate()
        let icon = springboard.icons[name]
        sleep(5)
        //let icon = springboard.icons.matching(identifier: "ONE").firstMatch
        //let icon = springboard.otherElements["Home screen icons"].scrollViews.otherElements.icons["ONE"]
        if icon.exists {

            let iconFrame = icon.frame
            let springboardFrame = springboard.frame

            //Tap & Hold the app icon in order to go to edit mode
            Thread.sleep(forTimeInterval: 0.5)
            icon.press(forDuration: 1.3)

            //Tap the little "X" button at approximately where it is. The X is not exposed directly
            Thread.sleep(forTimeInterval: 0.5)
            springboard.coordinate(withNormalizedOffset: CGVector(dx: (iconFrame.minX + 5) / springboardFrame.maxX, dy: (iconFrame.minY + 5) / springboardFrame.maxY)).tap()

            //tap the delete alert button
            Thread.sleep(forTimeInterval: 0.5)
            springboard.alerts.buttons["Delete"].tap()
        }

        //Press home once make the icons stop wiggling
        Thread.sleep(forTimeInterval: 0.5)
        XCUIDevice.shared.press(.home)
    }
}

【问题讨论】:

  • 执行这段代码时,在Springboard页面上是否可以看到app图标?
  • 不确定我是否理解正确。您是说在执行上述代码时,模拟器上是否可以看到应用程序图标?如果是,那么是的,它是可见的。否则我不明白你所说的跳板页面是什么意思。

标签: ios ui-automation xcuitest


【解决方案1】:

你可能会改变bundleIdentifier

let springboard = XCUIApplication(bundleIdentifier: "com.apple.springboard")


另外,您可以使用simctl 工具删除您的应用

xcrun simctl uninstall --help

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-10-27
    • 1970-01-01
    • 1970-01-01
    • 2020-09-14
    • 2020-06-11
    • 2021-11-21
    • 2016-11-15
    相关资源
    最近更新 更多