首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >springboard.icons["appName"]无法识别XCUITest中安装的应用程序

springboard.icons["appName"]无法识别XCUITest中安装的应用程序
EN

Stack Overflow用户
提问于 2019-08-05 13:22:36
回答 1查看 385关注 0票数 0

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

但是代码片段let icon = springboard.icons"myAppName“无法识别我的应用程序。我已经用我的应用程序名和检查icon.exists是否总是返回false的if条件替换了myAppName。springboard类如下所示。我是不是错过了什么。

代码语言:javascript
复制
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)
    }
}
EN

回答 1

Stack Overflow用户

发布于 2019-09-04 18:23:43

您可能需要更改bundleIdentifier

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

此外,您还可以使用simctl工具删除应用程序

xcrun simctl uninstall --help

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57352569

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档