springboard.icons [“ appName”]无法识别XCUITest中已安装的应用程序

时间:2019-08-05 05:22:35

标签: ios ui-automation xcuitest

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

但是代码片段let icon = springboard.icons [“ myAppName”]无法识别我的应用。我已经用我的应用程序名称和检查icon.exists是否始终返回false的if条件替换了myAppName。跳板类如下所示。我在这里想念什么吗?

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)
    }
}

1 个答案:

答案 0 :(得分:0)

您可能应该更改bundleIdentifier

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


此外,您可以使用simctl工具

删除您的应用

xcrun simctl uninstall --help